Reputation: 7
When I load Jquery from CDN, it is working but the problem is I cant do validation of fields that are defined in rules() method. But when I don't load custom Jquery version from CDN then validation is working.
Also, I am getting jQuery(...).yiiActiveForm is not a function in the console when I load Jquery from CDN and if I use inbuilt Jquery then no error.
Upvotes: 0
Views: 239
Reputation: 303
You can use jQuery.noConflict for your second, non-yii jQuery and use another var name instead of $. In this example i use jq
var jq = jQuery.noConflict();
// Do something with jQuery
jq( "div p" ).hide();
// Do something with another library's $()
$( ".content" ).hide();
You can add this line in your template after your tag with jQuery.
<script>var jq = jQuery.noConflict();</script>
If you use an Asset, just load an additional .js script with that line.
Anyway, you should avoid this entirely if you can.
From the documentation:
If for some reason two versions of jQuery are loaded (which is not recommended), calling $.noConflict( true ) from the second version will return the globally scoped jQuery variables to those of the first version.
Upvotes: 1