PDA

View Full Version : How to get both ValueField and displayField value in comboBox



bhanuprakash_kavi
8 Sep 2009, 8:09 AM
Hi all,

I am need to get both valueField and displayField values,

my Jsonstore returns a jsonArray like


Fields : ['countryId','countryName']
data : [[0,'india'],[1,'canada'] ....]
In comboBox I set as


displayField : 'countryName',
valueField : 'countryId',
I am able to get valueField value by


var value = Ext.getCmp('combo').getValue();

which returns (0) for India, and (1) for canada

I also need a displayField value (India)
please help me out....
Thanks in advance

bhanuprakash_kavi
8 Sep 2009, 8:23 AM
Hi all,

I found the solution.

to get the displayField value



Ext.getCmp('combo').getRawValue();

dlbjr
8 Sep 2009, 8:48 AM
I use the following function alot because some stores used with a Combo Box have more than two fields and have data I'm interested in not associated with the Combo Box.



function getCBSValue(cb, nameIn, nameOut){
try{
var r = cb.getStore().find(nameIn,cb.getValue());
return r.get(nameOut);
}
catch(err){
return 'error';
}
}

var item = getCBSValue(Ext.getCmp('combo'), 'countryId', 'countryName');

Zokol
4 Jul 2012, 1:54 AM
Thanks for the simple example for getting certain field from multiple field combobox store.
The previously posted function just didn't work with ExtJS 3.1.1, so here is the fixed version:



function getCBSValue(cb, nameIn, nameOut){
try{
var r = cb.getStore().find(nameIn,cb.getValue());
return cb.getStore().getAt(r).get(nameOut);
}
catch(err){
return'error';
}
}