PDA

View Full Version : [SOLVED] Combobox - selection by ID



mchrustek
7 Sep 2007, 1:01 AM
Hi.
I have something like this [combobox of course :)]:



var names = new Ext.form.ComboBox({
fieldLabel: 'Choose name',
hiddenName:'id',
store: new Ext.data.SimpleStore({
fields: ['id', 'name_value'],
data : comboBox.names
}),
displayField:'name_value',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Choose from the list...',
selectOnFocus:true,
width:175,
value: 'Mike'
});


names.js looks like this:


Ext.namespace('comboBox');

comboBox.names = [
['1', 'Mike'],
['2', 'Andrew'],
(...)

Instead of setting default selection by name (last row: value: 'Mike') I'd like to set default selected item by it's 'id', not by name. How can I do it? I tried all of 'select', 'setValue', selectByValue' etc.

Thank you very much for help.
Mike

fay
7 Sep 2007, 1:28 AM
You haven't included a valueField in your combo's config.




Ext.namespace('comboBox');

comboBox.names = [
[1, 'Mike'],
[2, 'Andrew'],
//...

var names = new Ext.form.ComboBox({
fieldLabel: 'Choose name',
hiddenName:'nameid',
store: new Ext.data.SimpleStore({
fields: ['id', 'name_value'],
data : comboBox.names
}),
displayField:'name_value',
valueField: 'id',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Choose from the list...',
selectOnFocus:true,
width:175,
value: 1
});

// ...

names.setValue(1);

Btw, I changed the data to integer (1) instead of string ('1').

mchrustek
7 Sep 2007, 1:43 AM
I've included 'hiddenName' and 'valueField', but for some reason I've deleted them while modyfying for the example included in this post (by mistake).
Of course 'names.setValue(1);' works perfectly. Thank you for your help.

Mike