PDA

View Full Version : ComboBox getValue returns display field value



bseddon
5 Apr 2012, 9:46 AM
Below is a definition for a store and combobox (don't comment on the style of the store definition this is generated by the designer). You can see that a the combobox is defined to use the 'value' field for it's value and the 'name' field as its display fields. However calls to comboBox.getValue(), comboxBox.getRawValue() and comboBox.getDisplayValue() all return the content of the 'name' field while I was expecting the getValue() and getRawValue() functions to return the value of the value field.

How should I be configuring the combobox so the getValue() function returns the value rather than the name?

I see the same behavior when using 4.0.7 and the nightly build from 0404.

ComboBox


{ xtype: 'combobox',
id: 'clusterTypes',
fieldLabel: 'Cluster type',
labelWidth: 70,
allowBlank: false,
editable: false,
autoSelect: false,
displayField: 'name',
store: 'ClusterTypes',
valueField: 'value'
}

Store:


Ext.define('CircularRelationships.store.ClusterTypes', { extend: 'Ext.data.Store',
requires: ['CircularRelationships.model.ClusterType'],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'ClusterTypes',
model: 'CircularRelationships.model.ClusterType',
data: [
{name: 'Name', value: 'name'},
{name: 'Popularity', value: 'popularity'},
{name: 'Related tags',value: 'tags'},
{name: 'Number of relationships',value: 'rels'}
],
proxy: {type: 'memory'}
}, cfg)]);
}
});

bseddon
5 Apr 2012, 9:52 AM
My own fault. The combo box does not default to the first item so it has to be populated in code. That code does sets only a 'name' not a 'value'.