0
$(function() {
    $('#dialog').click(function() {
      alert("hello");
    });    
});

$('select').yaselect();

I am genuinely confused about how javascript script inclusion works. So the click handler for the dialog works fine. But the yaselect does not. I get $("select").yaselect is not a function

So jQuery seems to work, but the yaselect somehow not. It is included in the head section of the file though.

<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/libs/jquery-1.7.2.min.js?"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/libs/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/libs/jquery.yaselect.min.js"></script>

However, the yii framework somehow includes jquery again later in the head section:

<script type="text/javascript" src="/assets/ab20866e/jquery.js"></script>
<script type="text/javascript" src="/assets/ab20866e/jquery.yiiactiveform.js"></script>

I understand this might be a problem, however I took over this code, I am new to yii and so am confused about what to do.

2
  • 1
    Check the url of the rendered web page and make sure that it's pointing at the correct folder for the 3 scripts. Commented Oct 9, 2012 at 16:28
  • @fablife, it's unusual but not unknown to need two versions of jQuery on the same page. If this was done intentionally, then there should be a var foo = jQuery.noConflict() statement after the first <script...></script> tag-pair and before the second. Otherwise, the second version will simply overwrite the first, such that the second endures for the life of the page. Commented Oct 9, 2012 at 16:33

2 Answers 2

2

This is due to the particular script which has yaselect(); implementation has not been included correctly. If you go through your javascript code you can find it where the code breaks. Click handler might be working fine because the jquery file has been imported correctly.

Also don't forget to check for jQuery duplicates and conflicts(Read more about noConflict()). This might cause the problem too. So make sure to remove the duplicates, in your case you have have included jquery as well as the framework too. Try to use a single version of jquery across the site.

if (jQuery) {
alert('jQuery is loaded!');
}

By using above code you can check whether the jquery has present in the page or not. If jquery does not exist in the page you can include.

0

http://www.yiiframework.com/wiki/311/assetmanager-clearing-browser-s-cache-on-site-update/

This appears to solve the problem. In Yii framework, you can use the AssetManager to handle static resources. If they then get referenced through the AssetManager instead of directly including them in the html source files, the yii framework takes care that resources are included once only.

Nice :)

2
  • 1
    Congrats fablife. To keep things tidy, you might like to accept your own answer. Commented Oct 9, 2012 at 16:46
  • Thanks! I'll be able to do that in 2 days :). Commented Oct 9, 2012 at 16:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.