View Full Version : ComboBox: setValue doesnt change selectedIndex

29 Jun 2010, 12:01 AM
How to change the value of the Ext.form.ComboBox in order to selectedIndex also changed?

I set value of the comboBox via setValue method.
But when I try to get corresponding data object in store for selected value:
comboStore.getAt(comboBox.selectedIndex).dataI receive wrong object, because of selectedIndex doesn't changed.

Oh, sh... I've mistaken of the forum section...
Please moderators remove this topic to Ext JS Community Forums (3.0).

29 Jun 2010, 12:31 AM
Correct. selectedIndex is only used when a selection from the dropdown list is made. You can't rely on it to contain the current index.

To locate the current record use:

var record = combobox.findRecord(combobox.valueField || combobox.displayField, combobox.getValue());

29 Jun 2010, 3:44 AM
ok, thanks

29 Jun 2010, 5:49 AM
It also seems one cannot trigger a selection change event by calling setValue("...."). The problem with that is now I have to tightly couple the event code that responds to gui events to the code that programmatically changes the value and that's generally not a good thing.

It would be nice if there is a value changed event that is triggered regardless of what manner the combo box value has changed, maintaining loose coupling.

1 Jul 2010, 12:49 PM
I agree... this is common question and confuses a lot of people...myself included :-P