PDA

View Full Version : setValue of a combobox with valueField



eaglefox12
26 Apr 2013, 11:37 AM
This is my model for my combo


Ext.define('ExtJS.myApp.ComboModel', {
extend: 'Ext.data.Model',
alias: 'widget.combomodel',
fields: [
{ name: 'ID', type: 'int' },
{ name: 'title', type: 'string' }
]
});

This is comboStore

this.comboStore = Ext.create('Ext.data.Store', {
model: 'ExtJS.myApp.ComboModel',
autoLoad: true,
scope: this,
proxy: {
type: 'ajax',
scope: this,
url: 'myApp/GetRecords',
reader: {
type: 'json',
root: 'data'
}
}
});


this.myComboBox = Ext.create('Ext.form.ComboBox', {
store: this.comboStore,
queryMode: 'local',
displayField: 'title',
valueField: 'ID'
});

This is the json object I get for my store:


{"ID":"111","title":"Ext Page 1"}

now when I try to set the value of the combobox like this.

this.myComboBox.setValue('111');

the combobox shows "111" instead of "Ext Page 1"

What would I have to do so that the combobox displays displayField while setting valueField

28 Apr 2013, 7:39 PM
Are you setting the value *before* the store loads? this problem is an indication that you probably are. :-?

girish.arjunagi
28 Apr 2013, 11:45 PM
Why don't you use this.myComboBox.select('111') function of combo.

eaglefox12
29 Apr 2013, 5:27 AM
Girish... thanks for your answer... I tried using select. It show up as '111' on the combobox. I actually want to show 'Ext Page 1'. And then when I try to save the value of the combobox. I want to save '111'. but either doing getRawValue or getValue gives me the displayField.

Why don't you use this.myComboBox.select('111') function of combo.

eaglefox12
29 Apr 2013, 5:30 AM
Hi Jay... I tried setting the value after loading the store too, but get the same result. However, when I select a different item from the dropdown, I get the id numbers. It's not giving the right value only when I am trying to set a default value.


Are you setting the value *before* the store loads? this problem is an indication that you probably are. :-?