0

I am using Select2 Widget In yii Framework and want to call function on change event but its not working

Yii::import('ext.select2.Select2');
 echo Select2::activeMultiSelect($categoryModel, "cat_name", CHtml::listData(
                            Category::model()->findAllByAttributes(array('cat_type' => 'Recipe')), 'id', 'cat_name'), array(
                'placeholder' => 'Select Category',
                'select2Options' => array(
                    'maximumSelectionSize' => 5,
                       'events' => array('change' => 'js:function(){ alert("asdfasdfasdfasdfasdf"); }')
                ),
            ));

i am going to alert message on change but this not works and not show any error message or something on console thanks in advance

lin
  • 17,956
  • 4
  • 59
  • 83
FahadAkram
  • 445
  • 1
  • 5
  • 25

1 Answers1

1

You can try adding an id to your select, then bind your function to its click event with jQuery like this in the footer of your page:

$("#selectID").click(function () {
    alert("Selected value is: " + $("#selectID").select2("val"));
});
Nail
  • 464
  • 7
  • 19
  • forgot to pass id and call function on that id , but the thing in my mind is to call its events like on change and i was stuck there , i need to think out of box – FahadAkram Aug 21 '14 at 05:52