PDA

View Full Version : ComboBox Id-Value Problem



casbar
19 Aug 2009, 8:31 AM
Hello,
I have a combobox with a such a json store:



Array
(
[priority] => Array
(
[0] => Array
(
[id] => 0
[name] => Yesterday
)

[1] => Array
(
[id] => 1
[name] => Today
)

)

)



In the hiddenField i put the "id" because only the id has to been saved into the database.
The display is also ok, because I set as valueField the "name", but when I save it to the databse and reload the form, in the combobox will be the "id" and not the "name" so in this case a "1" or a "0"...
Why?

the combobox code:



return new Ext.form.ComboBox({
hiddenName: 'testcombo',
width: 200,
store: new Ext.data.JsonStore({
url: 'myurl.php',
root: 'priority',
autoLoad: true,
fields: ['id', 'name']
}),
mode: 'remote',
valueField: 'id',
displayField: 'name',
allowBlank: false,
triggerAction: 'all',
editable: false,
selectOnFocus: true
});

dlbjr
19 Aug 2009, 8:41 AM
I could be wrong, but I believe the store is not loading until the Combobox is selected due to mode: 'remote' . Change this to mode: 'local' which will cause the store to load immediately and see what happens.

casbar
20 Aug 2009, 12:11 AM
Sorry but it doesn't make difference!!
Other ideas? :)

dlbjr
20 Aug 2009, 5:10 AM
Is the value in the json a number or a string. Try wrapping it in single quotes and make it a string.

lpastor
20 Aug 2009, 6:28 AM
Hello

I don't no why, but don't use : mode

I use that :


{fieldLabel: 'nom', name: 'nom_application', width:300, allowBlank: false},
new Ext.form.ComboBox({
fieldLabel: 'Statut',
hiddenName:'id_statut_application',
store: store_statut,
valueField:'id_statut',
displayField:'nom_statut',
typeAhead: false,
triggerAction: 'all',
emptyText:'Vide...',
selectOnFocus:true,
width:200
}),
{xtype:'datefield', fieldLabel: 'Date', name: 'dateheure_application', width:100,format:'d/m/Y'},
new Ext.form.Checkbox({fieldLabel: 'Visible', /*boxLabel: 'Visible',*/ name: 'visible_application' }),

avsomeren
20 Aug 2009, 6:37 AM
just add mode:'local' to the config of the combo and see what happens