2011-01-17 4 views
0

Je viens de commencer avec Dojo et mon problème est le suivant: J'ai un FiltringSelect, où ma recherche utilise l'idée d'un comme% john%.dijit.form.FilteringSelect sélectionnant la mauvaise valeur

donc mon filtre sélectionnera et la valeur avec "john" dans la liste, donc après écriture john je peux avoir une liste comme:

Andrew John
John
John Alen
Simon John

Donc, l'idée "j'aime" fonctionne bien.
Le problème est: lorsque j'écris "john" et appuyez sur Entrée. Le nom sélectionné est toujours le premier de la liste par exemple "Andrew John" et non le second qui correspond exactement. Quelqu'un at-il une ideia comment résoudre ce problème?

Merci

Répondre

0

Le behaivour normal du FilteringSelect est d'obtenir toujours le premier élément du combobox. Parce que généralement c'est le match exact. En raison du fait que ma serach était "comme" dans le texte, le premier élément n'est pas toujours exactement le macth. Donc, pour résoudre mon problème, j'ai changé le FilteringSelect.js, donc je vérifie si l'option combobox correspond exactement et retourne cet élément. Dans mon cas, la correspondance exacte peut être la deuxième, la troisième ... dans la liste des combobox. s'il n'y a pas je retourne le premier (comme c'était avant).

Voici le code:

> _callbackSetLabel: function( /*Array*/ result, 
         /*Object*/ dataObject, 
         /*Boolean?*/ priorityChange){ 
    // summary: 
    //  Callback function that dynamically sets the label of the 
    //  ComboBox 
    // setValue does a synchronous lookup, 
    // so it calls _callbackSetLabel directly, 
    // and so does not pass dataObject 
    // still need to test against _lastQuery in case it came too late 

if((dataObject && dataObject.query[this.searchAttr] != this._lastQuery) || (!dataObject && result.length && this.store.getIdentity(result[0]) != this._lastQuery)){ 
       return; 
    } 
      if(!result.length){ 
       //#3268: do nothing on bad input 
       //#3285: change CSS to indicate error 
       this.valueNode.value = ""; 
       dijit.form.TextBox.superclass._setValueAttr.call(this, "", priorityChange || (priorityChange === undefined && !this._focused)); 
       this._isvalid = false; 
       this.validate(this._focused); 
       this.item = null; 
      }else{   
       //because the combobox have a like of the word the first element may no be the exact match 
       for(var j = 0; j < result.length; j++) {     
        //check if in the result there is the text that the user typed 
        if(dataObject && result[j].i["id"].toLowerCase() === dataObject.query[this.searchAttr].toLowerCase()) 
        { 
         //return the exact match 
         this.set('item', result[j], priorityChange); 
         return; 
        }     
       } 
       // if there isn't a exact match return the first of the list 
       this.set('item', result[0], priorityChange);     
      } 
     }, 
Questions connexes