How to get the value of selected displayField in ExtJS 3.4 ComboBox? getValue() returns valueField, but I need other.
Asked
Active
Viewed 3.0k times
5
-
Ok, whatever `valueField` is in your case can you clarify what you need then? – sra Jan 14 '13 at 09:57
-
ComboBox has displayField that shown on the page and valueField that submited to script. I need to get value of displayField of selected item. – Argnist Jan 14 '13 at 10:07
-
For that there is no easy way to archive this. You can subscribe yourself to the select event, but that will only fire if a user clicks and not it you set the value using `setValue()`. So you will need to extend the combo class to add such a behavior. Dunno if that is an option for you, but the is no other way – sra Jan 14 '13 at 10:14
-
There is an other way. calling [getRawValue()](http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.ComboBox-method-getRawValue) – A1rPun Jan 14 '13 at 10:16
-
getRawValue() returns valueField value :( – Argnist Jan 14 '13 at 10:24
-
And store is remote so with getStore().load() need callback function contained other parts of the script. I think it is wrong... – Argnist Jan 14 '13 at 10:28
-
This is what I meant with [getRawValue() (JSFIDDLE)](http://jsfiddle.net/nFDPx/1/). – A1rPun Jan 14 '13 at 13:01
4 Answers
6
If this is the case,
displayField : 'countryName',
valueField : 'countryId',
then following function gives the required displayFiled (Even more than 1 fields are there in store you can get them too)
function getFieldValues(combo, nameIn, nameOut){
try{
var r = combo.getStore().find(nameIn,combo.getValue());
return combo.getStore().getAt(r).get(nameOut);
}
catch(err){
return'error';
}
}
Way to get the displayfield or any other filed which is in store :
var item = getFieldValues(Ext.getCmp('combo'), 'countryId', 'countryName');

vajrakumar
- 758
- 2
- 7
- 21
0
Maybe u just user store.filter(), right? If that, try clear filter and load again like below:
onProvinceSelected: function (com,record,index)
{
var provinceCode = com.getValue();
var postGrid = this.lookupReference('postgrid');
if (provinceCode != 0) {
postGrid.store.filter('ProvinceCode', provinceCode);
} else {
postGrid.store.filters.clear();
postGrid.getStore().load();
}
}

SysDragon
- 9,692
- 15
- 60
- 89
0
I'm using the lastSelectionText property of the ComboBox; works fine for me, but it is an undocumented feature and thus may break at any time...
Ext.override(Ext.form.ComboBox,
{
getDisplayValue: function () {
return this.lastSelectionText;
}
});

wexman
- 1,217
- 10
- 19