Ticket #5974: 5974.3.patch

File 5974.3.patch, 3.8 kB (added by haysmark, 7 months ago)

Fixes #5974. FilteringSelect? now respects required=false. setValue(null) clears the input. Also addressed a related bug in ComboBoxDataStore? that sent all items to the ComboBox? on a totally blank query.

  • form/ComboBox.js

     
    10631063                //      summary:  
    10641064                //              See dojo.data.util.simpleFetch.fetch() 
    10651065                if(!args.query){ args.query = {}; } 
    1066                 if(!args.query.name){ args.query.name = "*"; } 
     1066                if(!args.query.name){ args.query.name = ""; } 
    10671067                if(!args.queryOptions){ args.queryOptions = {}; } 
    10681068                var query = "^" + args.query.name 
    10691069                                .replace(/([\\\|\(\)\[\{\^\$\+\?\.\<\>])/g, "\\$1") 
  • form/FilteringSelect.js

     
    2929                // 
    3030                _isvalid:true, 
    3131 
     32                required:true, 
     33 
    3234                _lastDisplayedValue: "", 
    3335 
    3436                isValid:function(){ 
    35                         return this._isvalid; 
     37                        return this._isvalid||(!this.required&&this.getDisplayedValue()==""); // #5974 
    3638                }, 
    3739 
    3840                _callbackSetLabel: function(    /*Array*/ result,  
     
    4547                        // setValue does a synchronous lookup, 
    4648                        // so it calls _callbackSetLabel directly, 
    4749                        // and so does not pass dataObject 
    48                         // dataObject==null means do not test the lastQuery, just continue 
    49                         if(dataObject && dataObject.query[this.searchAttr] != this._lastQuery){ 
     50                        // still need to test against _lastQuery in case it came too late 
     51                        if((dataObject && dataObject.query[this.searchAttr] != this._lastQuery)||(!dataObject&&this.store.getIdentity(result[0])!= this._lastQuery)){ 
    5052                                return; 
    5153                        } 
    5254                        if(!result.length){ 
    5355                                //#3268: do nothing on bad input 
    5456                                //this._setValue("", ""); 
    5557                                //#3285: change CSS to indicate error 
    56                                 if(!this._focused){ this.valueNode.value=""; } 
    57                                 dijit.form.TextBox.superclass.setValue.call(this, undefined, !this._focused); 
     58                                if(!this._focused){ this.valueNode.value=null; } 
     59                                dijit.form.TextBox.superclass.setValue.call(this, null, !this._focused); 
    5860                                this._isvalid=false; 
    5961                                this.validate(this._focused); 
     62                                this.item=null; 
    6063                        }else{ 
    6164                                this._setValueFromItem(result[0], priorityChange); 
    6265                        } 
     
    7477 
    7578                getValue:function(){ 
    7679                        // don't get the textbox value but rather the previously set hidden value 
    77                         return this.valueNode.value; 
     80                        return this.isValid()?this.valueNode.value:null; 
    7881                }, 
    7982 
    8083                _getValueField:function(){ 
     
    9497                        // summary 
    9598                        //      Sets the value of the select. 
    9699                        //      Also sets the label to the corresponding value by reverse lookup. 
     100                        this._lastQuery=value; 
     101                        // #5974: setValue(null) should clear input 
     102                        if(!value){ 
     103                                this.setDisplayedValue("",priorityChange); 
     104                                return; 
     105                        } 
    97106 
    98107                        //#3347: fetchItemByIdentity if no keyAttr specified 
    99108                        var self=this; 
     
    178187                                        }, 
    179188                                        onError: function(errText){ 
    180189                                                console.error('dijit.form.FilteringSelect: ' + errText); 
    181                                                 dojo.hitch(_this, "_setValue")(undefined, label, false); 
     190                                                dojo.hitch(_this, "_setValue")(null, label, false); 
    182191                                        } 
    183192                                }); 
    184193                        } 
  • tests/form/test_FilteringSelect.html

     
    6868        <hr> 
    6969 
    7070        <form action="#" method="GET"> 
    71                 <p>FilteringSelect #1: inlined data, autoComplete=false:</p> 
     71                <p>FilteringSelect #1: inlined data, autoComplete=false, required="false":</p> 
    7272                <label for="setvaluetest2">state list 1:</label> 
    7373                <select dojoType="dijit.form.FilteringSelect" 
    7474                                id="setvaluetest2" 
     
    7878                                onChange="dojo.byId('oc1').value=arguments[0]" 
    7979                                onFocus="console.log('user focus handler')" 
    8080                                onBlur="console.log('user blur handler')" 
     81                                required="false" 
    8182                > 
    82                         <option value="blank"></option> 
    8383                        <option value="AL">Alabama</option> 
    8484                        <option value="AK">Alaska</option> 
    8585                        <option value="AS">American Samoa</option>