PDA

View Full Version : Combobox doesn't work as expected with valueField



threethazz
2 Nov 2011, 5:52 AM
Hello,

I'm having an interesting "feature" with my combobox. This combobox needs to:
1) have a displayField and a valueField [not sure if working]
2) allow selection of other values from the list [not working]
3) automatically load one value to the box. [working]

What happens in Point (2) is that the drop down shows me 3 correct values but after selection actually doesn't update the value chosen in the box nor fires the alert message.

here's some code:


if (!Ext.ClassManager.isCreated('Company')){
Ext.define('Company',{
extend: 'Ext.data.Model',
fields: [
'name', 'company_id',
]
});
}
var companiesStore = Ext.create('Ext.data.Store', {
model: 'Company',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'Company',
reader: {
type: 'json',
root: 'list'
} }
});


companiesStore.on({
'load': {
fn: function(companiesStore){
customTplCombo.setValue(companiesStore.getAt(0).get('company_id')); }, scope:this }
});


var customTplCombo = Ext.create('Ext.form.field.ComboBox', {
id: 'combobx',
fieldLabel: 'Select a Company',
renderTo: 'ComboBox',
displayField: 'name',
valueField: 'company_id',
hiddenName: 'company_id',
width: 300,
labelWidth: 130,
store: companiesStore,
allowBlank: false,
queryMode: 'local',
listeners:{
scope: this,
'select': function(){
var comboV = Ext.getCmp('combobx');
alert(comboV.getRawValue());
}
}
});

Thank you in advance!
threethazz

threethazz
2 Nov 2011, 6:06 AM
When I comment the line of valueField: 'company_id', the combo box works (allows me to select other values) but it doesnt have any id value nor it automaticaly selects the first value as default.

skirtle
2 Nov 2011, 8:08 AM
Could you post the JSON that's coming from the server? The symptoms suggest there may be a problem with the company_id field.

threethazz
2 Nov 2011, 8:14 AM
Thank you for your reply :)

the JSON returns the expected list. But I managed to solve the issue. The list returns "companyId" instead of "company_id". I've corrected this in the code and now it's working.

Stupid me I forgot to check that.

Thank you for your reply!
threethazz.