Changeset 13989

Show
Ignore:
Timestamp:
06/12/08 19:07:26 (5 months ago)
Author:
bill
Message:

Support required=true/false parameter for FilteringSelect? so that a blank entry in the dropdown list is not necessary. Patch from Mark Hays (IBM, CCLA on file). Fixes #5974 !strict.
Also some cleanup so that onChange() and getValue() return "" for when the input field is blank/invalid. (Before I had thought to return null in those cases but "" seems better.) Refs #5919.

Location:
dijit/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • dijit/trunk/form/ComboBox.js

    r13979 r13989  
    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 
  • dijit/trunk/form/FilteringSelect.js

    r13269 r13989  
    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 
     
    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                        } 
     
    5557                                //#3285: change CSS to indicate error 
    5658                                if(!this._focused){ this.valueNode.value=""; } 
    57                                 dijit.form.TextBox.superclass.setValue.call(this, undefined, !this._focused); 
     59                                dijit.form.TextBox.superclass.setValue.call(this, "", !this._focused); 
    5860                                this._isvalid=false; 
    5961                                this.validate(this._focused); 
     62                                this.item=null; 
    6063                        }else{ 
    6164                                this._setValueFromItem(result[0], priorityChange); 
     
    9598                        //      Sets the value of the select. 
    9699                        //      Also sets the label to the corresponding value by reverse lookup. 
     100                        this._lastQuery=value; 
     101 
     102                        if(!value){ 
     103                                this.setDisplayedValue("",priorityChange); 
     104                                return; 
     105                        } 
    97106 
    98107                        //#3347: fetchItemByIdentity if no keyAttr specified 
     
    179188                                        onError: function(errText){ 
    180189                                                console.error('dijit.form.FilteringSelect: ' + errText); 
    181                                                 dojo.hitch(_this, "_setValue")(undefined, label, false); 
     190                                                dojo.hitch(_this, "_setValue")("", label, false); 
    182191                                        } 
    183192                                }); 
  • dijit/trunk/tests/form/test_FilteringSelect.html

    r13944 r13989  
    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" 
     
    7979                                onFocus="console.log('user focus handler')" 
    8080                                onBlur="console.log('user blur handler')" 
    81                 > 
    82                         <option value="blank"></option> 
     81                                required="false" 
     82                > 
    8383                        <option value="AL">Alabama</option> 
    8484                        <option value="AK">Alaska</option>