Ensure the [font="Lucida Console"]tags[/font] should return a single dimensional array (and not an associative array) something like [font="Lucida Console"]["red", "blue", "green"][/font]. Check the details at the plugin site.
In additon, note that when you are using the TAGS method the values are NOT STORED as an ARRAY. Instead its stored as a COMMA SEPARATED text (or any separator you choose).
So remember to pass the value from your model accordingly to the input if you wants tags shown preselected. Similarly, when you read you need to convert the comma separated tag list to an array and store if needed.
One way to do it is override the [font="Lucida Console"]createSearchChoice[/font] in [font="Lucida Console"]pluginOptions[/font]… read more about this on plugin site:
However, the better way IMO, would be to use a normal multiple selection list, which will appear like tags in Select2 widget, but will allow only specific defined tags to be selected. just define it like a normal dropdown list with
Seems some javascript error on your client – as the plugin is not initialized – can you get the Javascript error from your browser error console (e.g. using Firebug for mozilla).
my code works well for saving and preload data which is already saved in db.
_form
<?php
//these are the data I need to preload from DB table
$arrayVal = explode(',',$model->listofparties);//split as array
$arrayFlip = array_flip($arrayVal); //reverse key =>value
//List organisation items/data
$matchOrg = CHtml::listData(Organisation::model()->findAll('active =1'), 'id','name');
//match from actual items/data with data in db table, retrieve which is match only
$arrayFinalMatch = (array_intersect_key($matchOrg, $arrayFlip));//get macth key and retrieve value
//set as selected value.
$selected = $arrayFinalMatch;
$options = array();
foreach ($selected as $key => $value) {
//here I create an array suitable for the 'options' attribute with my data marked as selected
$options[$key]=array('selected'=>true);
}
// Working with model
$this->widget('bootstrap.widgets.TbSelect2',array(
'model'=>$model,
'attribute'=>'listofparties',
'data'=>CHtml::listData(Organisation::model()->findAll('active =1'), 'id','name'),
//'val'=>'0,1,2',
'htmlOptions' => array(
'options'=>$options, //the selected values
'multiple' => true,
'placeholder' => 'Type here ...',
),
'options' => array(
'width' => '90%',
'height'=>'50px',
//'maximumSelectionSize' => 8,
'tokenSeparators' => array(',', ' ')
),
));
?>
in Controller
//TbSelect2 for the list parties for Tower
if(is_array($model->listofparties)){//check is data is array (value is selected)
$model->listofparties = implode(",",$model->listofparties);
}else{//check is data is NOT array (value is NOT selected- empty)
$model->listofparties = '';
}
I hope my code will help others to stop cracking head…! haha