ExtJS ComboBox shows value instead of text
January 4th, 2008While developing an app for a client, I came across a problem with ExtJS's form handling.
Let's say you have a form with a Ext.form.ComboBox on it.
When the form's load() function is called, it sets the values of the fields on the form to the data retrieved from the form's store.
Now, if your ComboBox is pulling its data from a standard lookup table, it will usually be setup as a value/text pair.
Problem is that the form displays the value, and not the text associated with that value.
I suspected that the ComboBox had not loaded its data before the form tried to fill in the field value.
This was confirmed by watching the XMLHTTPRequests in FireBug, and also by setting the valueNotFoundText config for the ComboBox to something arbitrary like 'Not found'.
True enough, when I loaded the page again, the ComboBox field displayed 'Not found', despite being loaded with a valid value.
Poring over the code and documentation showed no way of configuring the ComboBox to immediately load and associate itself with the data store.
So I've resorted to doing this instead:
-
var form = new Ext.form.FormPanel({
-
...
-
listeners:{
-
actioncomplete:function(form, action) {
-
if(action.type=='load') {
-
form.items.each(function(item, index, length) {
-
if(item.xtype=='combo') {
-
item.doQuery(item.allQuery, true);
-
item.setValue(item.getValue());
-
}
-
}
-
}
-
}
-
}
-
...
-
});
Note that this will probably only work if you use xtype's to define your form fields. YMMV.
It's a bit of a kludge, but it works well enough for me, until I figure out how to do it another more convenient way.