开发者

dijit.form.FilteringSelect selecting wrong value

I just start with 开发者_如何学PythonDojo and my problem is the follow: I have a FilteringSelect, where my search uses the idea of a like %john%.

So my filter will select and value with "john" in the list, so after write john I can have a list as:

Andrew John

John

John Alen

Simon John

So the "like" idea works fine.

The problem is: when I write "john" and press enter. The selected name is always the first in the list for instance "Andrew John" and not the second that is an exact match. Any one has an ideia how to solve this problem?

Thank you


The normal behaivour of the FilteringSelect is always get the first element of the combobox. Because usually this is the exact match. Due the fact that my serach was "like" in the text the first element is not always the exact macth.

So, to solve my problem I changend the FilteringSelect.js, so I do a check to see if in the combobox option there is an exact match and return this element. The my case the exact match can be the second, third... in the combobox list. if there isn't I return the first one (as was before).

Here the 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);                
            }
        },
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜