Ticket #6338: DropDownSelect.patch

File DropDownSelect.patch, 2.4 kB (added by nathan, 10 months ago)

Patch which adds rough "required" support to DropDownSelect?. Since an empty box is disabled, it might get a bit weird with multiple invalid elements...

  • dojox/form/DropDownSelect.js

     
    55 
    66dojo.require("dojo.data.ItemFileWriteStore"); 
    77 
     8dojo.requireLocalization("dijit.form", "validate"); 
     9 
    810dojo.declare("dojox.form.DropDownSelect", dijit.form.DropDownButton, { 
    911        // summary: 
    1012        //              This is a "Styleable" select box - it is basically a DropDownButton which 
    1113        //              can take as its input a <select>. 
    1214 
    1315        baseClass: "dojoxDropDownSelect", 
     16         
     17        // required: Boolean 
     18        //              Can be true or false, default is false. 
     19        required: false, 
    1420 
     21        // state: String 
     22        //              Shows current state (ie, validation result) of input (Normal, Warning, or Error) 
     23        state: "", 
     24 
     25        //      tooltipPosition: String[] 
     26        //              See description of dijit.Tooltip.defaultPosition for details on this parameter. 
     27        tooltipPosition: [], 
     28 
    1529        /*===== 
    1630        dojox.form.__SelectOption = function(){ 
    1731                //      value: String 
     
    176190                } 
    177191        }, 
    178192         
     193        validate: function(/*Boolean*/ isFocused){ 
     194                // summary: 
     195                //              Called by oninit, onblur, and onkeypress. 
     196                // description: 
     197                //              Show missing or invalid messages if appropriate, and highlight textbox field. 
     198                var isValid = this.isValid(isFocused); 
     199                this.state = isValid ? "" : "Error"; 
     200                this._setStateClass(); 
     201                dijit.setWaiState(this.focusNode, "invalid", isValid ? "false" : "true"); 
     202                var message = isValid ? "" : this._missingMsg; 
     203                if(this._message !== message){ 
     204                        this._message = message; 
     205                        dijit.hideTooltip(this.domNode); 
     206                        if(message){ 
     207                                dijit.showTooltip(message, this.domNode, this.tooltipPosition); 
     208                        } 
     209                } 
     210                return isValid;          
     211        }, 
     212 
     213        isValid: function(/*Boolean*/ isFocused){ 
     214                // summary: Whether or not this is a valid value 
     215                return (!this.required || !/^\s*$/.test(this.value)); 
     216        }, 
     217         
     218        reset: function(){ 
     219                // summary: Overridden so that the state will be cleared. 
     220                this.inherited(arguments); 
     221                dijit.hideTooltip(this.domNode); 
     222                this.state = ""; 
     223                this._setStateClass(); 
     224                delete this._message; 
     225        }, 
     226 
     227        postMixInProperties: function(){ 
     228                // summary: set the missing message 
     229                this.inherited(arguments); 
     230                this._missingMsg = dojo.i18n.getLocalization("dijit.form", "validate",  
     231                                                                        this.lang).missingMessage; 
     232        }, 
     233 
    179234        _fillContent: function(){ 
    180235                // summary:   
    181236                //              Loads our options and sets up our dropdown correctly.  We