Ext-JS setValue method for ComboBox Control
Trying to set the selected value of a ComboBox control in Ext-JS 2.2, I found out that it was trying to set the selection before it was actually populated. This in-turn appended the value into the ComboBox. Ext's FAQ lists a patch to work around this, but it took some searching to find this solution. You will need to overwrite the setValue method that will listen for the store to be populated.
setValue : function(v){
//begin patch
// Store not loaded yet? Set value when it *is* loaded.
// Defer the setValue call until after the next load.
if (this.store.getCount() == 0) {
this.store.on('load',
this.setValue.createDelegate(this, [v]), null, {single: true});
return;
}
//end patch
var text = v;
if(this.valueField){
var r = this.findRecord(this.valueField, v);
if(r){
text = r.data[this.displayField];
}else if(this.valueNotFoundText !== undefined){
text = this.valueNotFoundText;
}
}
this.lastSelectionText = text;
if(this.hiddenField){
this.hiddenField.value = v;
}
Ext.form.ComboBox.superclass.setValue.call(this, text);
this.value = v;
}
});

