Dropdown list with autocomplete

Hi!

I need a special dropdown widget or some advice on how to create it.

Here’s a background of a story.

I’m having like two Models. One has_many other. And this many is reeeealy many.

There’s no point in rendering regular dropdown list with 1000 or more options in it.

So I need a dropdown list that will allow me to type some text before it suggests me an options list.

But it should pass id in the end.

Like on facebook.

like this one?

http://www.yiiframework.com/doc/api/1.1/CJuiAutoComplete

i think that you need something as

http://www.yiiframework.com/extension/combobox/

hope it helps!

regards!

:)

That one its not a true dropdownlist, it only as a value field, and what i need is a pair id -> value/label where the id was passed to the database and the value is only to view purposes.

Anyone knows how to do that with a dropdown not a simple textfield.

May be try this

jsearchdropdown.sourceforge.net

I think the suggestion of Attilio is a good one and you can store id with it.

How do i define what will be stored as ID and how can i retrieve it??

Thanks in advance!

You can use select options




'city_id' => array(

                    'type'=>'zii.widgets.jui.CJuiAutoComplete',

                    'source'=>Yii::app()->createUrl('ajax/autocomplete'),

                    'options'=>array(

                        'select'=>'js:function(event, ui) {

                            $("#hidden_city_id").val(ui.item.id);

                            return true;

                        }',

                    ),                 

                ),



Don`t forget create hidden filed


<input id="hidden_city_id" name="Orders[city_id]" type="hidden" />