I am trying to use "SELECT2" extension with YII. I followed the tutorial step by step but it's not working. The drop-down list for auto-complete doesn't appear and I am getting this error in chrome console...
The controller code (HotelController)
public function actionTitleName(){
$model =HotelEn::model()->findAll ('Title like :Title',array(':Title'=>"%".$_GET['q']."%"));
$result = array();
foreach ($model as $HotelEn){
$result[] = array(
'id'=>$HotelEn->id,
'term'=>$RoomEn->Number,
);
}
echo CJSON::encode($result);
}
the view code (_roomearch)
echo CHtml::beginForm(CHtml::normalizeUrl(array('Hotel/create')), 'get', array('id'=>'filter-form'))
. '<div class="row" style="width:100%;">'
. CHtml::encode('Hotel Name')
. CHtml::textField('Number',(isset($_GET['Number'])) ? $_GET['Number'] : '',array('id'=>'Number'));
$this->widget('ext.select2.ESelect2',array(
'selector' => '#Title',
'options' => array(
'allowClear'=>true,
'placeholder'=>'Select a Hotel Name',
'minimumInputLength' => 2,
'ajax' => array(
'url' => Yii::app()->createUrl('Hotel/Number'),
'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>'
I ran into the same problem today. I received the "Uncaught TypeError: Object [object Object] has no method 'select2'" error message in my browser console as well as a warning about a deprecated method in another .js file I was referencing (http://code.jquery.com/jquery-1.9.1.js). Turns out I wasn't even using it! so I deleted the script which referenced it, removing the warning.
Fixing the warning made my select2 problem go away.
a few things to help you trace what's wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With