A jQuery combobox, allowing selecting items from a list or typing them in. This is done by combining a select, text field, and button.
As it extends the included JUI widget, theming will respect your customizations.
Developed and tested on Yii 1.1.7, should work on any 1.1.x branch.
Extract to your extensions folder.
In your view file :
$this->widget('ext.combobox.EJuiComboBox', array( 'model' => $myModel, 'attribute' => 'myAttribute', // data to populate the select. Must be an array. 'data' => array('yii','is','fun','!'), // options passed to plugin 'options' => array( // JS code to execute on 'select' event, the selected item is // available through the 'item' variable. 'onSelect' => 'alert("selected value : " + item.value);', // JS code to be executed on 'change' event, the input is available // through the '$(this)' variable. 'onChange' => 'alert("changed value : " + $(this).val());', // If false, field value must be present in the select. // Defaults to true. 'allowText' => false, ), // Options passed to the text input 'htmlOptions' => array('size' => 10), ));
Total 14 comments
I have error when i multiply use this extension in modal windows,it's error like this
Object this - undefined in function destroy Error somewhere here i think (extension/combobox/assets/jquery.ui.combobox.js) :
[js] destroy: function() { this.input.remove(); this.button.remove(); this.element.show(); $.Widget.prototype.destroy.call(this);Any ideas? P.S. Sorry for my English.
Hi, Toph.
Thank you for your contribution.
I found a small bug:
You shoud use
Instread of
CHtml::resolveValue helps you to avoid errors in complex forms.
The original jQuery combobox allows for separate key=>value pairs. In order to add this functionality to the combobox I added a public property $assoc and the run() method has to be changed as follows:
Full code on GitHub
IMPORTANT the combobox input field has "_combobox" appended to its id. The select now has the original name and id of the field.
Shout out to @_construct() for the bug fix.
An example of the usage is below
Thanks.
Is it possible to use this extension as nested dropDownList..? for example i want to list the city for state which was selected in the 1st select box(normal dropDownList).. if the city not listed user have option to type it down..
add sourceUrl to EJuiComboBox.php
in jquery.ui.combobox.js
widget:
create a action that returns json:
/...../
json looks like this (example)
is it possible to use a ajax autocomplete as data? which e.g. only starts searching after X characters given?
What are the "public $scriptSelector;" property and "protected function setSelector" method for?
how about multi select? will it be possible?
Hi, i like this extension but, someone can make an example of it with a database plz. I don't understand how to build it.
best regards. ( sorry for my bad english too ^^ )
The combobox is a text field, so you can't use it like a select where the option value is different from the option text.
Maybe a normal select is a better option for you.
Another solution is make a custom JS function to update a hidden field with the value you need. You can then call this method through the 'onSelect' and/or 'onChange' events.
HTH
Hi, I wanna use this combobox with the following data strucure
Customer CustomerGroup customer_group_id customer_group_id cus_gro_name
I want the field cus_gro_name to be displayed, BUT the value to be stored is the customer_goup_id.
Thank you very much for your help!
Cheers Phil
Sorry there was an error in the sample, the correct variable to send the array to is 'data'.
I looked for this component so hard! Can you build a Sample with a separate Key => Value sample? If possible;)
Cheers Phil
Leave a comment
Please login to leave your comment.