Typeerror Has No Method 'select2'

I am traying to use “SELECT2” extenssion with YII. I folowed the tuto step by step but it’s not working.

The dropdownlist for autocoplete doesn’t apear and I am getting this erro in chrome console


Uncaught TypeError: Object [object Object] has no method 'select2' 

What I am doing wrong please ?

Thank you.

The controller code (HavesController)


	public function actionTitleName(){

		$model =PropProjectEn::model()->findAll ('Title like :Title',array(':Title'=>"%".$_GET['q']."%")); 

		$result = array();

		foreach ($model as $PropProjectEn){

			$result[] = array(

				'id'=>$PropProjectEn->id,

				'term'=>$PropUnitEn->TitleName,

			); 

		}

		echo CJSON::encode($result);

	}

the view code (_propertysearch)




	echo CHtml::beginForm(CHtml::normalizeUrl(array('Haves/create')), 'get', array('id'=>'filter-form'))

		. '<div class="row" style="width:100%;">'

		. CHtml::encode('Project Title')

		. CHtml::textField('TitleName',(isset($_GET['TitleName'])) ? $_GET['TitleName'] : '',array('id'=>'TitleName'));

	$this->widget('ext.select2.ESelect2',array(

		'selector' => '#Title',

		'options'  => array(

			'allowClear'=>true,

			'placeholder'=>'Select a Project Name',

			'minimumInputLength' => 2, 

			'ajax' => array(

				'url' => Yii::app()->createUrl('Haves/TitleName'),

				'type'=>'GET',

				'dataType' => 'json',

				'quietMillis'=> 100,

				'data' => ' function(term,page) {

					return {

						//get im my controller

						q: term, 

					};

				}',

				'results'=>'function(data,page) { return {results: data, more:more }; }',

			),

		),

	));         

	echo '</div>'

If you are including in your page 2 versions of jquery this error may occur.

Call the scriptmap in your controller action and set it to false specifying the jquery files to stop the jquery registered by the extension:


 

      Yii::app()->clientScript->scriptMap = array(

        'jquery.js' => false,

        'jquery-ui.min.js' => false,

    );



thank you for the reply.

I added your scrip to controller action but still get the same error

Sorry Im a newbie with yii


 public function actionTitleName(){

                    

$model =PropProjectEn::model()->findAll ('Title like :Title',array(':Title'=>"%".$_GET['q']."%")); 

                   $result = array();

                   foreach ($model as $PropProjectEn){

           $result[] = array(

                        'id'=>$PropProjectEn->id,

                        'term'=>$PropUnitEn->TitleName,

           ); 

        }

                echo CJSON::encode($result);  


      Yii::app()->clientScript->scriptMap = array(

        'jquery.js' => false,

        'jquery-ui.min.js' => false,

    );	

Please, put the clientscript code in the action that renders the view containing the widget not in the action that echo the json.

Or you can put it in the view directly

can you please show me if you don’t mind.

sorry for bothering you.

thank you

Put the clientscript in the action that is providing the view _propertysearch

example if your action name is select then the action code :




public function actionSelect(){

   Yii::app()->clientScript->scriptMap = array(

        'jquery.js' => false,

        'jquery-ui.min.js' => false,

    );

  $this->render("_propertysearch");

   

}

Hope this help you :)

thank you for your help :)

but in my file _prppertysearch I have alot of other filer it’s not the only one (other dropdownlist, texfields etc) and they all are in actionCreate in the controller

but for this one the action is TitleName, so should put it inside actionCreate or actionTitleName ?

sorry for the noobie questions