By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,854 Members | 869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,854 IT Pros & Developers. It's quick & easy.

how to create dependent ajax combobox using jquery/yii extension?

P: 1
how to create depending ajax combobox(like this http://jqueryui.com/resources/demos/.../combobox.html with autocomplit). using jquery (or using yii extension)??

i'm using this extension (based by jquery ui combobox)
(http://www.yiiframework.com/extension/combobox)

this my code:

Expand|Select|Wrap|Line Numbers
  1. City select:
  2. <?
  3. $this->widget('ext.combobox.EJuiComboBox', array(
  4.     'model' => $model,
  5.     'attribute' => 'city',
  6.     // data to populate the select. Must be an array.
  7.     'data' => Chtml::listData( City::model()->findAll(), 'name', 'name'),
  8.     'options' => array(
  9.         'onChange' => CHtml::ajax(array(
  10.             'type'=>'get',
  11.             'dataType'=>'json',
  12.             'url'=> 'object/add',
  13.             'data' =>array('city'=>'js:$(this).val()'),
  14.             'success' => 'js:function(data) { console.log(data.distrincts) ; }',
  15.  
  16.         )),
  17.         'allowText' => false,
  18.     ),
  19.     // Options passed to the text input
  20.     'htmlOptions' => array('size' => 10),
  21. ))
  22. ?>
I'm sending ajax-request in controller when combobox are changed and gettind distrinct list (by city) in 'success' function in json format, but it's possible dynamically update 'data' field in another combobox(like first):

Expand|Select|Wrap|Line Numbers
  1. $this->widget('ext.combobox.EJuiComboBox', array(
  2.     'model' => $model,
  3.     'attribute' => 'district',
  4.     'data' => array(),
  5.     'options' => array(
  6.         'allowText' => false,
  7.     ),
  8.     'htmlOptions' => array('size' => 10),
  9. ))
Maybe not using this yii extension, only jquery ui combobox, but i can't find solution for jquery combobox too.
Dec 12 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.