PDA

View Full Version : How do you get the Displayed Field value from a combobox?



hannas
21 Jan 2011, 8:00 AM
Hello,

I am using a comboBox and I use the getValue() method which works well, but I also want to use the displayed text for the item I selected. How do I get that?

Regards,

hannas
21 Jan 2011, 11:37 AM
I've got it!!
You get the selected text from the store.


var cms_committee_record = Ext.data.Record.create([
{
name: 'key'
},
{
name: 'committee'
}
]);
...

var key= Ext.getCmp(comboBoxId).getValue();
var rindex= cms_committee_store.find('key',key);
var cRecord = cms_committee_store.getAt(rindex);
var selectedText = cRecord.get('committee');

rivarecords
21 Jan 2011, 11:49 AM
Yep, that's it and then you could add a method:



{xtype: 'combo',
fieldLabel:'Some Combo',
id:'some_combo',
store: some_combo_store,
mode:'local',
valueField: 'value',
displayField: 'text',
getDisplayedText: function(v) {
var val = this.valueField;
var text = this.displayField;
var cbval = this.value;
var displayedText = '';
Ext.each(this.store.getRange(0,this.store.getCount()), function(row){
if(row.get(val)==cbval){displayedText = row.get(text)}
})
return displayedText;
}
}

And then call it like:

var selectedText = Ext.getCmp(some_combo).getDisplayedText()

darthwes
21 Jan 2011, 8:05 PM
Store.getById