PDA

View Full Version : Default value of combobox



oneofthelions
3 Feb 2011, 3:38 AM
I have local var (Array list) which has three key, value pairs.

I want the second value to be displayed in the combo box and its key as default.



Ext.onReady(function(){

var group = [['brand', 'Product'],['site', 'Location'],['environment', 'Environment']];
Ext.QuickTips.init();

var store = new Ext.data.ArrayStore({
fields: ['abbr', 'group'],
data : group
});
var combo = new Ext.form.ComboBox({
store: store,
displayField:'group',
typeAhead: true,
mode: 'local',
forceSelection: true,
triggerAction: 'all',
emptyText:'Location', //So the 'Location' which is second value is to be displayed. And its key 'site'
selectOnFocus:true,
applyTo: 'local-states'
});
combo.selectByValue('site', true);
});

fay
3 Feb 2011, 4:41 AM
Add a valueField (http://dev.sencha.com/deploy/dev/docs/?class=Ext.form.ComboBox&member=valueField) config param?



var combo = new Ext.form.ComboBox({
//... As before
valueField: 'abbr'
});
combo.selectByValue('site', true);

Condor
3 Feb 2011, 4:45 AM
Yes, you should specify valueField:'abbr', but also replace emptyText:'Location' with value:'site'.