This extension is a wrapper for Chosen JavaScript plugin which makes long, unwieldy select boxes much more user-friendly.
Tested with Yii 1.1.10, but should work with previous versions too
Example:
$this->widget('ext.chosen.Chosen',array( 'name' => 'inputName', // input name 'value' => '2', // selection 'data' => array( // list of select options '1'=>'Option 1', '2'=>'Option 2', '3'=>'Option 3', '4'=>'Option 4', ), ));
Before this import ext.chosen.Chosen, you can add it to config/main.php or call Yii::import('ext.chosen.Chosen') before usage.
Chosen::dropDownList($name, $select, $data, $htmlOptions); Chosen::activeDropDownList($model, $attribute, $data, $htmlOptions); Chosen::multiSelect($name, $select, $data, $htmlOptions); Chosen::activeMultiSelect($model, $attribute, $data, $htmlOptions);
Total 6 comments
Got some issues when needed to disable search on some selects and found out that you dont have such features. So here is some code :
In file Chosen.php init() function add
Then in your view :
You can do same for all other features. Hope it will be usefull for someone.
Still don't work with double quotes.
So i find that in all CHtml active widgets, they use
In the documentation of resolveNameID
So i add the
in your function and now it works.
I'm new in YII, so i don't know if it was the right thing to do.
Widget supports tabular input(CHtml::activeName, is used to resolve input name), seems problem is in quotes used for attribute name, try with double quotes: Chosen::activeDropDownList($car, "[$i]state", $list, $htmlOptions);
I can't use Chosen::activeDropDownList($car, '[$i]state', $list, $htmlOptions);
Thanks.
Because there are separate properties in widget, to change this settings: ($placeholderMultiple, $placeholderSingle, $allowSingleDeselect, $noResults). Also some properties have internationalized default values(originally script has no i18n).
If I have missed some configuration options: add issue or make pull request on bitbucket - I will add them.
You saved my life, dude!
Just one question:
Why property $settings is set as private in Chosen.php? Are there other ways to pass the javascript options to .chosen({$settings})?
Thanks a lot!
Leave a comment
Please login to leave your comment.