5
votes

How to get the value of selected displayField in ExtJS 3.4 ComboBox? getValue() returns valueField, but I need other.

4
Ok, whatever valueField is in your case can you clarify what you need then?sra
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
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 waysra
There is an other way. calling getRawValue()A1rPun
getRawValue() returns valueField value :(Argnist

4 Answers

21
votes

combo.getValue() -> the valueField
combo.getRawValue() -> the displayField

6
votes

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');
0
votes

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();
    }
}
0
votes

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;
    }
});