Sandy
Sandy

Reputation: 466

Set Combobox value using the display value

I have a combobox whose values are unknown to me. I know only the display values. Without going through the datastore of the combobox and finding the rawvalue-value maps, is there any other easier way to set the combobox by its raw value.

Let's say these are options:

 Display: 'A' Value: '1'
 Display: 'B' Value: '2'
 Display: 'C' Value: '3'

When I use

 Ext.getCmp(comboboxId).setRawValue('A')

The above code does set the display value to 'A', but when I checked it's corresponding value, it doesn't change to '1'.

Upvotes: 0

Views: 2142

Answers (3)

CD..
CD..

Reputation: 74156

You can use findRecordByDisplay for finding the record:

Finds the record by searching values in the displayField.

then select it using select:

Selects an item by a Model, or by a key value.

For example:

var cmp = Ext.getCmp(comboboxId),
    record = cmp.findRecordByDisplay('A');

cmp.select(record);

Upvotes: 3

DanielS
DanielS

Reputation: 774

setValue can accept either valueField or displayField values. Link.

setRawValue only sets the 'displayField. It doesn't callconvert` function or raise any events

Upvotes: 0

LightNight
LightNight

Reputation: 851

You don't need to walk through datastore manually.

var record = store.find("field","value");
Ext.getCmp(comboboxId).select(record);

Upvotes: 2

Related Questions