Javascript – EXTJS Combobox not selecting by valueField after expand


I have written some code that works pretty well, but I have a strange bug
Here is an example…


Like I said, this works well every time datachanged fires – the right index is selected and the displayField is displayed but, everytime after I type some text in the combobox, later, when the "datachanged" fires, it wont display the displayField. Instead, it displays the value from the setValue method I launch.

The strange thing is that if I don't ever type text and change the selection with the mouse there is no bug. Finally, this appears only when I type text in the combobox.

Has anyone heard of this bug, have a solution, or some wise advice?

The Code !

Two data stores :

ficheDataStore = new{
    id: 'ficheDataStore',
    autoLoad: true,
    proxy: new{
        url: 'ficheDetail.aspx',      // File to connect to
        method: 'GET'
    baseParams: { clientId: clientId, Type: 'Fiche' }, // this parameter asks for listing
    reader: new{   // we tell the datastore where to get his data from
        root: 'results'
    }, [
        { name: 'GUID', type: 'string', mapping: 'GUID' },
        { name: 'TagClient', type: 'string', mapping: 'TagClient' },
        { name: 'Nom', type: 'string', mapping: 'Nom' },
        { name: 'Compteur', type: 'string', mapping: 'CompteurCommunes' },
        { name: 'CompteurCommunesFacturation', type: 'string', mapping: 'CompteurCommunesFacturation' },
        { name: 'AdresseFacturation', type: 'string', mapping: 'AdresseFacturation' },
        { name: 'Codes', type: 'string', mapping: 'Codes' },
        { name: 'Observations', type: 'string', mapping: 'Observations' },
        { name: 'Adresse', type: 'string', mapping: 'Adresse' }


 communesDataStore = new{
    autoLoad: true,
    proxy: new{ url: 'ficheDetail.aspx?Type=Communes' }),
    reader: new{ root: 'results' }, [{ name: 'Compteur' }, { name: 'Localisation'}])

Who return something like this for the

  {results:[{"Nom":"cercle interieur"},{"Observations":""},{"Codes":" "},{"Adresse":"dd"},{"CompteurCommunes"

For the latter :

{"results":[{ "Compteur" : "1","Localisation" : "6200  ST ISIDORE"},{ "Compteur" : "2","Localisation"
 : "21340 CHANGE"},{ "Compteur" : "3","Localisation" : "1200  ELOISE"},{ "Compteur" : "4","Localisation"
 : "1200  ST GERMAIN SUR RHONE"},{ "Compteur" : "5","Localisation" : "75000 PARIS"},{ "Compteur" : "6"
,"Localisation" : "75001 PARIS 1ER ARRONDISSEMENT"}]}

a Combobox :

 var comb = new Ext.form.ComboBox(
               store: communesDataStore,
               fieldLabel: 'Code postal',
               // hiddenName: 'Compteur',
               name: 'CompteurCommune',
               id: 'CompteurCommunes',
               width: 300,
               typeAhead: true,
               mode: 'local',
               minChars: 0,
               selecOnFocus: true,
               forceSelection: true,
               valueField: 'Compteur',
               displayField: 'Localisation',
               autocomplete: true,
               emptyText: 'Selectionnez un code postal',
               triggerAction: 'all',
               value: ''

in a datachanged event i set the new value of the Combobox "CompteurCommunes" :

   ficheDataStore.addListener('datachanged', handleDatachangedEvent);

     function handleDatachangedEvent() 
        try {
        catch (err) { }

Best Answer

It's probably because when you type random data into combo, it may not locate correct fieldValue every time. Then it stucks at the last non-existing value.

Try to set ComboBox to any existing value (in combo's datastore) before doing new setValue() in your datachanged event handler. Or you can try to use clearValue() method to reset the previous (undefined) valueField.

There also initList() method existing to reset combo to initial state.

EDIT: After some testing, I found that:; must be used before setValue in the external event handler.

Related Topic