ExtJs didn't fire select event on ComboBox

Afshin Mehrabani picture Afshin Mehrabani · Jan 10, 2013 · Viewed 22.5k times · Source

I have a problem with ExtJs combobox, consider I have a combobox that has 4 items and a callback function in select event on combobox.

When I'm going to set the combobox selected value with setValue(), ExtJs don't fire select event.

How can I fix this problem?

Should I fire this event after setValue() by myself?

Answer

sra picture sra · Jan 10, 2013

I can tell you what the sencha support told for that one year ago:

Well, event is, by definition, a function call triggered by a user action and there's no user action when you call select.

Anyway, the "fix" is easy: you know that you call select so just after calling select you can call your select listener function.

It depends on your case what you should do. For me I hanged my implementation so that I was able to call re responsible method but on the other hand I don't see any downside when you fire the event yourself. So I think it is up to you which approach you like more.

Here is a example how you can fire the event by yourself (partly from the comment by @JohanHaest)

To make it simple I say you have only single selection enabled

var record = combo.store.getById(id);
combo.select(id);
combo.fireEvent('select', combo, record);

or

combo.select(model);
combo.fireEvent('select', combo, model);

There is a possible Hack in the current release (4.1.3) when setting a second argument on the select method to true. This will, according to the sourcecode, fire the select event. But the First argument has to be a Model instance.

// source-snipped
select: function(r, /* private */ assert)

So calling

combo.select(model, true);

will fire the select event but this behavior may change at any time (version) cause the assert is marked as private