PDA

View Full Version : ComboBox getDisplayedValue - How?



TheRebelGriz
20 May 2007, 11:36 AM
Using Ext - 1.0.1a:

Given the following SimpleStore and ComboBox Definition:


var dAttrTYpes = [ ['DIVISION', 'Divisions'], ['STATE', 'State Attrs'],['MISC', 'Miscellaneous'] ];

var store = new Ext.data.SimpleStore({ fields: ['attr_type', 'description'], data: dAttrTYpes });
var cbAttrType = new Ext.form.ComboBox(
{ store: store
, label: 'Select Attr'
, displayField:'description'
, valueField: 'attr_type'
, typeAhead: true
, mode: 'local'
, triggerAction: 'all'
, emptyText:''
, selectOnFocus: true
, setEditable: false
}
);

How does one go about getting the DisplayedValue of the selectedItem ?

For Example:
1. A User selects 'State Attrs' in the comboBox.
2. I then need to show a MessageBox that shows the display value of the selected Item in the ComboBox..

cbAttrType.getValue() which returns ''STATE'' but I 'State Attrs' instead.

Any assistance is appreciated!
Thanks in Advance!!

TheRebelGriz
21 May 2007, 5:59 AM
The following is a work-around that allows me to getDisplayed Value provided that I don't have duplicate 'attr_type' in my SimpleStore:



var store = new Ext.data.SimpleStore({ fields: ['attr_type', 'description'], data: dAttrTYpes });
var cbAttrType = new Ext.form.ComboBox(
{ store: store
, displayField:'description'
, valueField: 'attr_type'
, typeAhead: true
, mode: 'local'
, triggerAction: 'all'
, emptyText:''
, selectOnFocus: true
, setEditable: false
}
);


cbAttrType.store.filter( 'attr_type' , cbAttrType.getValue() );
var displayText = store.getAt(0).get('description');
cbAttrType.store.clearFilter();

francescoNemesi
21 May 2007, 9:56 AM
I have achieved that using the getRawValue() method of the combobox:

var dispValue = cbAttrType.getRawValue();

it should work.

Francesco