Default value for EXTJS combobox after form layout

My combobox data is loaded after the layout of the form.

var villeStore = new Ext.data.ArrayStore({ fields: [{name:'idVille'} ,{name: 'ville'}] }); var villeInput = new Ext.form.ComboBox({ fieldLabel: 'Ville', store: villeStore, valueField:'idVille', displayField:'ville', typeAhead: true, mode: 'local', triggerAction: 'all', emptyText:'Ville', width:100, id:'villeInput' }); 

The problem is that I need to display the last one from the repository, but even have the Field value, because when I click on the button, this is what I send to the server

I did this, but it does not work, it shows the last value of the store, but it does not matter

 villeInput.store.on('load',function(store) { villeInput.setValue(store.getAt(villeInput.store.getCount()-1).get('ville')); }); 
+4
source share
2 answers

The problem is that you need to set the combo value using valueField ( idVille ) instead of displayField :

 villeInput.store.on('load',function(store) { villeInput.setValue(store.getAt(villeInput.store.getCount()-1).get('idVille')); }); 
+4
source

Try the following:

  villeInput.store.on("load", function(store) { villeInput.setValue(ActualidVille, false); }, this); 
+1
source

All Articles