Select2 Has Prepopulated Values?

Hi,

I declare a select2 as follows in my view:


                        

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

     'model'=>$model,

     'attribute'=>'Areas',

     'data'=>CHtml::listData(Fishingarea::model()->findAll(), 'AreaID', 'AreaName'),

     'options'=>array(

       'width'=>'200px',

       'allowClear'=>true,

     ),

     'htmlOptions'=>array('multiple'=>'multiple',),

));



For some reason when the form is rendered (created, not editing), the select2 component is prepopulated with values. I want it to be empty. I am really not sure what to do. Can anyone advise? Thanks!

if you dont want the options to be pre-populated, you can set data to an empty array

Thanks for your response, but how would I populate the values I want to populate the listbox with? setting data to an empty array will show nothing. Am I missing something?

Sifa I did not understand what you were trying to achieve, If I am not mistaken you want first item to be empty so its default to empty you can simply merge an empty array with your data set, or alternatively just set the select2 placeholder option to something like "please select"


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

     'model'=>$model,

     'attribute'=>'Areas',

     'data'=>CHtml::listData(Fishingarea::model()->findAll(), 'AreaID', 'AreaName'),

     'options'=>array(

       'width'=>'200px',

       'placeholder'=>' -- please select -- ', // add this line

       'allowClear'=>true,

     ),

     'htmlOptions'=>array('multiple'=>'multiple',),

));



Thanks again Alirz23 … problem turned out to be that I did not define a model property called Areas (i did at one point but it got deleted in a crazy clean-up exercise). This resulted in the select2 being populated with some values. But thanks also for the feedback … i am using the placeholder option now … neat! New to yii and loving it.

btw, I am from cpt :)