PDA

View Full Version : Ext.form.ComboBox setValue() doesn't update display



moses.yang
21 Mar 2012, 7:49 AM
I have a combobox like below (Ext 4.0.3)
var cityComboBox = Ext.create('Ext.form.ComboBox', {
id: 'cityCombo',
fieldLabel: 'City',
store: cityStore,
labelWidth : 180,
disabled : true,
width: 280,
name : 'cityId',
queryMode: 'local',
displayField: 'name',
valueField: 'id',
listeners:{
'change' : function(combo, newValue, oldValue){

}
}
});

and a Country combobox similar like the cityComboBox to choose a country trigger enable to set city in above city combobox. Country has its own default city logic as a capital. However, setValue with a city id didn't update the display of city combo box. Even cityComboBox.getValue() is correct. It is a bug or not. If it is't, how to resolve that?

mitchellsimoens
21 Mar 2012, 11:45 AM
I have not had this issue in any version that I have used (have had PR, beta and everything)

moses.yang
21 Mar 2012, 4:54 PM
Let me explain

At beginning the city combo box is disabled, once the country combo box selected, then the city combo box is enable and load data via AJAX way. Then I invoked the setValue() with a default value according to selected country. As result, the value is set, but display still nothing.

Anyone, help me out, I have been struggle in this issue for days.

vietits
21 Mar 2012, 4:59 PM
Try to call setValue() after the store bound to city combobox has finished its loading.

moses.yang
21 Mar 2012, 5:14 PM
Here is my code to set the default value
loadCities(); //An Ajax request to load data. it was loaded up
cityComboBox.enable();
if( cityChanged ){
cityComboBox.setValue(row.get("cityId"));//Fetch default city id from a country record
console.log(invoiceTermComboBox.getValue());//It logged a correct value
}

Is there anything I missed order?

vietits
21 Mar 2012, 5:22 PM
Here is my code to set the default value
loadCities(); //An Ajax request to load data. it was loaded up
cityComboBox.enable();
if( cityChanged ){
cityComboBox.setValue(row.get("cityId"));//Fetch default city id from a country record
console.log(invoiceTermComboBox.getValue());//It logged a correct value
}
Is there anything I missed order?

If you do this way, the cityComboBox.setValue() may be executed before the cityStore completes its loading. You should wait for 'load' event of cityStore and then do the setting value.

moses.yang
21 Mar 2012, 6:00 PM
Thanks, it makes sense. Could you show me how to listen the event when the store is loaded up?

vietits
21 Mar 2012, 6:44 PM
function onStoreLoaded(){
...
}
cityStore.on('load', onStoreLoaded);