Igor Savinkin
Igor Savinkin

Reputation: 6277

Select2 jquery function is undefined when changing layout

I've changed the layout file in yii and now the problem with identifying the select2 function. enter image description here I've checked the source code - seems identical in both cases. In both of them the select2.js is present: <script type="text/javascript" src="/app3/assets/b92019fc/select2.js"></script>

Source code of one where the problem appears:

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" type="image/ico" href="/app2/img/favicon.ico">

 some css files are here... 

<script type="text/javascript" src="/app3/assets/df744518/jquery.js"></script>
<script type="text/javascript" src="/app3/assets/df744518/jquery.ba-bbq.js"></script>
<script type="text/javascript" src="/app3/assets/df744518/jui/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="/app3/assets/df744518/jquery.yii.js"></script>
<script type="text/javascript" src="/app3/assets/b92019fc/select2.js"></script>
<title>tarex. Page3</title>

 some css files are here... 

<script src="js/jquery.js"></script>
<script src="js/bootstrap.js"></script> 
    <script type="text/javascript" src="assets/35648952/jquery.yii.js"></script>
<script type="text/javascript">
jQuery(function($) {    
    jQuery('body').on('change','#_lang',function(){jQuery.yii.submitForm(this,'',{});return false;}); 
 jQuery('body').on('change','#Cityes_Name',function(){jQuery.yii.submitForm(this,'',{});return false;});
}); 
</script>
<script language='javascript'>       
            var RoleId=1; 
            var UserName='admin'; 
            var UserId='36'; 
            var OrganizationId='7'; 
            var Language='ru'; 
            //console.log('Language '+Language);</script>
</head>

The source code where there is no problem:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="language" content="en" /> 
<link rel="shortcut icon" type="image/ico" href="/app2/img/favicon.ico">

<script language='javascript'>       
            var RoleId=1; 
            var UserName='admin'; 
            var UserId='36'; 
            var OrganizationId='7'; 
            var Language='ru'; 
            //console.log('Language '+Language);</script>
    <!-- blueprint CSS framework --> 
 some css files are here... 

<script type="text/javascript" src="/app3/assets/df744518/jquery.js"></script>
<script type="text/javascript" src="/app3/assets/df744518/jquery.ba-bbq.js"></script>
<script type="text/javascript" src="/app3/assets/df744518/jquery.yii.js"></script>
<script type="text/javascript" src="/app3/assets/b92019fc/select2.js"></script>
<title>Главное меню</title>

</head>

What might be the problem in?

Upvotes: 0

Views: 356

Answers (1)

Justinas
Justinas

Reputation: 43507

You are applying jQuery few times. Load jQuery only once with Yii::app()->clientScript->registerCoreScript('jQuery')

Upvotes: 1

Related Questions