PDA

View Full Version : Ext 3.1 - Setting a value of Combo Box:



thursday
8 Jan 2010, 3:46 AM
I use combo box to display a list of countries in which valueField uses
countryCode and displayField uses countryName from the array store.

I collect all the form fields values at one place and initializes them. It works
fine for other types of fields except combo box.

Could you please let me know how do I initialize the value
of the combo when using valueField/displayField mode?




var countries = new Ext.data.ArrayStore({
fields: ['countryCode', 'countryName'],
data : [
['US', 'United States of America'],
['UK', 'United Kingdom']
]
});

var countryCombo = new Ext.form.ComboBox({
name: 'countryName',
allowBlank:false,
width: 150,
store: countries,
displayField:'countryName',
valueField: 'countryCode',
hiddenName: 'countryHiddenName',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Select Country',
selectOnFocus:true
});


var values =
{
city: 'Santa Clara',
countryName: 'United States of America',
countryHiddenName: 'United States of America'
}

formPanel.getForm().setValues (values);

BitPoet
8 Jan 2010, 5:49 AM
var values =
{
city: 'Santa Clara',
countryName: 'United States of America',
countryHiddenName: 'United States of America'
}

formPanel.getForm().setValues (values);


Did you try


var values =
{
city: 'Santa Clara',
countryName: 'US'
}

? Though the combo lets the user select the country's name, its value is a country code and it expects one of those in the call to setValue.

thursday
8 Jan 2010, 6:26 AM
Dear BitPoet,

Thanks for the pointer.


var values =
{
city: 'Santa Clara',
countryName: 'US'
}did not work. Then, I tried with



var values =
{
city: 'Santa Clara',
countryHiddenName: 'US'
}
It worked!.

Thanks a lot..