PDA

View Full Version : Default selection on a combo box



kenwood
23 Feb 2010, 2:53 PM
This should be a very simple but I could not figure it out. I have defined a combobox and would like this combobox to display a default selection. The data store is defined as follow:

createStore: function () {
var countryStore = new Ext.data.SimpleStore( {
fields: ['country', 'abbr'],
data: [ ['United States', 'US'], ['Canada', 'CA'] ]
});
return countryStore;
}

I tried calling setValue('US') and setValue('United States') but they both failed to work. I am wondering if this is even the right way to do it. Any suggestions?

bclinton
23 Feb 2010, 4:52 PM
It doesn't have anything to do with your issue, but SimpleStore is now known as ArrayStore so you should probably get used to writing that

What are you calling setValue on, the Store or the ComboBox? You should be calling it on the ComboBox. Also, when are you calling it? before or after the store loads?

kenwood
24 Feb 2010, 7:16 AM
I set the value of the combobox, after the store is set as below. In both cases, getValue return what I was setting the combobox with. What am I doing wrong?

Ext.apply(this, {
store: this.createStore()
});
alert('current value is (' + this.getValue() + ')');
// test1
// Ext.apply(this, {
// value: ['US']
// });

//test2
//this.setValue('United States');

alert('new value is (' + this.getValue() + ')');