dijit/form/ValidationTextBox.js

  • Provides:

    • dijit.form.ValidationTextBox
  • dijit.form.ValidationTextBox

    • type
      Function
    • chains:
      • dijit.form.TextBox: (prototype)
      • dijit.form.TextBox: (call)
    • summary
      Base class for textbox widgets with the ability to validate content of various types and provide user feedback.
      tags:
      protected
    • source: [view]
         this.constraints = {};
  • dijit.form.ValidationTextBox.templateString

    • summary
  • dijit.form.ValidationTextBox.baseClass

    • summary
  • dijit.form.ValidationTextBox.required

    • type
      Boolean
    • summary
      User is required to enter data into this field.
  • dijit.form.ValidationTextBox.promptMessage

    • type
      String
    • summary
      If defined, display this hint string immediately on focus to the textbox, if empty.
      Also displays if the textbox value is Incomplete (not yet valid but will be with additional input).
      Think of this like a tooltip that tells the user what to do, not an error message
      that tells the user what they've done wrong.
      
      Message disappears when user starts typing.
  • dijit.form.ValidationTextBox.invalidMessage

    • type
      String
    • summary
      The message to display if value is invalid.
      The translated string value is read from the message file by default.
      Set to "" to use the promptMessage instead.
  • dijit.form.ValidationTextBox.missingMessage

    • type
      String
    • summary
      The message to display if value is empty and the field is required.
      The translated string value is read from the message file by default.
      Set to "" to use the invalidMessage instead.
  • dijit.form.ValidationTextBox.message

    • type
      String
    • summary
      Currently error/prompt message.
      When using the default tooltip implementation, this will only be
      displayed when the field is focused.
  • dijit.form.ValidationTextBox.constraints

    • type
      Object
    • summary
  • dijit.form.ValidationTextBox.regExp

    • tags: extension protected
    • type
      String
    • summary
      regular expression string used to validate the input
      Do not specify both regExp and regExpGen
  • dijit.form.ValidationTextBox.regExpGen

    • type
      Function
    • parameters:
      • constraints: (typeof dijit.form.ValidationTextBox.__Constraints)
    • source: [view]
         return this.regExp; // String
    • summary
      Overridable function used to generate regExp when dependent on constraints.
      Do not specify both regExp and regExpGen.
    • tags:
    • returns
      String
  • dijit.form.ValidationTextBox.state

    • tags: readonly
    • type
      String
    • summary
      Shows current state (ie, validation result) of input (""=Normal, Incomplete, or Error)
  • dijit.form.ValidationTextBox.tooltipPosition

    • type
      String[
    • summary
      See description of `dijit.Tooltip.defaultPosition` for details on this parameter.
  • dijit.form.ValidationTextBox._setValueAttr

    • type
      Function
    • source: [view]
         this.inherited(arguments);
         this.validate(this._focused);
    • summary
      Hook so set('value', ...) works.
  • dijit.form.ValidationTextBox.validator

    • type
      Function
    • parameters:
      • value: (typeof anything)
      • constraints: (typeof dijit.form.ValidationTextBox.__Constraints)
    • source: [view]
         return (new RegExp("^(?:" + this.regExpGen(constraints) + ")"+(this.required?"":"?")+"$")).test(value) &&
          (!this.required || !this._isEmpty(value)) &&
          (this._isEmpty(value) || this.parse(value, constraints) !== undefined); // Boolean
    • summary
      Overridable function used to validate the text input against the regular expression.
    • tags:
  • dijit.form.ValidationTextBox._isValidSubset

    • type
      Function
    • source: [view]
         return this.textbox.value.search(this._partialre) == 0;
    • summary
      Returns true if the value is either already valid or could be made valid by appending characters.
      This is used for validation while the user [may be] still typing.
  • dijit.form.ValidationTextBox.isValid

    • type
      Function
    • parameters:
      • isFocused: (typeof Boolean)
    • source: [view]
         return this.validator(this.textbox.value, this.constraints);
    • summary
      Tests if value is valid.
      Can override with your own routine in a subclass.
    • tags:
  • dijit.form.ValidationTextBox._isEmpty

    • type
      Function
    • parameters:
      • value: (typeof )
    • source: [view]
         return (this.trim ? /^\s*$/ : /^$/).test(value); // Boolean
    • summary
      Checks for whitespace
    • returns
      Boolean
  • dijit.form.ValidationTextBox.getErrorMessage

    • type
      Function
    • parameters:
      • isFocused: (typeof Boolean)
    • source: [view]
         return (this.required && this._isEmpty(this.textbox.value)) ? this.missingMessage : this.invalidMessage; // String
    • summary
      Return an error message to show if appropriate
    • tags:
    • returns
      String
  • dijit.form.ValidationTextBox.getPromptMessage

    • type
      Function
    • parameters:
      • isFocused: (typeof Boolean)
    • source: [view]
         return this.promptMessage; // String
    • summary
      Return a hint message to show when widget is first focused
    • tags:
    • returns
      String
  • dijit.form.ValidationTextBox._maskValidSubsetError

    • summary
  • dijit.form.ValidationTextBox.validate

    • type
      Function
    • parameters:
      • isFocused: (typeof Boolean)
    • source: [view]
         var message = "";
         var isValid = this.disabled || this.isValid(isFocused);
         if(isValid){ this._maskValidSubsetError = true; }
         var isEmpty = this._isEmpty(this.textbox.value);
         var isValidSubset = !isValid && isFocused && this._isValidSubset();
         this._set("state", isValid ? "" : (((((!this._hasBeenBlurred || isFocused) && isEmpty) || isValidSubset) && this._maskValidSubsetError) ? "Incomplete" : "Error"));
         dijit.setWaiState(this.focusNode, "invalid", isValid ? "false" : "true");


         if(this.state == "Error"){
          this._maskValidSubsetError = isFocused && isValidSubset; // we want the error to show up after a blur and refocus
          message = this.getErrorMessage(isFocused);
         }else if(this.state == "Incomplete"){
          message = this.getPromptMessage(isFocused); // show the prompt whenever the value is not yet complete
          this._maskValidSubsetError = !this._hasBeenBlurred || isFocused; // no Incomplete warnings while focused
         }else if(isEmpty){
          message = this.getPromptMessage(isFocused); // show the prompt whenever there's no error and no text
         }
         this.set("message", message);


         return isValid;
    • summary
      Called by oninit, onblur, and onkeypress.
    • description
      Show missing or invalid messages if appropriate, and highlight textbox field.
    • tags:
  • dijit.form.ValidationTextBox.displayMessage

    • type
      Function
    • parameters:
      • message: (typeof String)
    • source: [view]
         dijit.hideTooltip(this.domNode);
         if(message && this._focused){
          dijit.showTooltip(message, this.domNode, this.tooltipPosition, !this.isLeftToRight());
         }
    • summary
      Overridable method to display validation errors/hints.
      By default uses a tooltip.
    • tags:
  • dijit.form.ValidationTextBox._refreshState

    • type
      Function
    • source: [view]
      define("dijit/form/ValidationTextBox", ["dojo", "dijit", "text!dijit/form/templates/ValidationTextBox.html", "dojo/i18n", "dijit/form/TextBox", "dijit/Tooltip", "i18n!dijit/form/nls/validate"], function(dojo, dijit) {




       dijit.form.ValidationTextBox.__Constraints = function(){
        // locale: String
        //  locale used for validation, picks up value from this widget's lang attribute
        // _flags_: anything
        //  various flags passed to regExpGen function
        this.locale = "";
        this._flags_ = "";
       }




      dojo.declare(
       "dijit.form.ValidationTextBox",
       dijit.form.TextBox,
       {
        // summary:
        //  Base class for textbox widgets with the ability to validate content of various types and provide user feedback.
        // tags:
        //  protected


        templateString: dojo.cache("dijit.form", "templates/ValidationTextBox.html"),
        baseClass: "dijitTextBox dijitValidationTextBox",


        // required: Boolean
        //  User is required to enter data into this field.
        required: false,


        // promptMessage: String
        //  If defined, display this hint string immediately on focus to the textbox, if empty.
        //  Also displays if the textbox value is Incomplete (not yet valid but will be with additional input).
        //  Think of this like a tooltip that tells the user what to do, not an error message
        //  that tells the user what they've done wrong.
        //
        //  Message disappears when user starts typing.
        promptMessage: "",


        // invalidMessage: String
        //   The message to display if value is invalid.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the promptMessage instead.
        invalidMessage: "$_unset_$",


        // missingMessage: String
        //   The message to display if value is empty and the field is required.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the invalidMessage instead.
        missingMessage: "$_unset_$",


        // message: String
        //  Currently error/prompt message.
        //  When using the default tooltip implementation, this will only be
        //  displayed when the field is focused.
        message: "",


        // constraints: dijit.form.ValidationTextBox.__Constraints
        //  user-defined object needed to pass parameters to the validator functions
        constraints: {},


        // regExp: [extension protected] String
        //  regular expression string used to validate the input
        //  Do not specify both regExp and regExpGen
        regExp: ".*",


        regExpGen: function(/*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to generate regExp when dependent on constraints.
         //  Do not specify both regExp and regExpGen.
         // tags:
         //  extension protected
         return this.regExp; // String
        },


        // state: [readonly] String
        //  Shows current state (ie, validation result) of input (""=Normal, Incomplete, or Error)
        state: "",


        // tooltipPosition: String[]
        //  See description of `dijit.Tooltip.defaultPosition` for details on this parameter.
        tooltipPosition: [],


        _setValueAttr: function(){
         // summary:
         //  Hook so set('value', ...) works.
         this.inherited(arguments);
         this.validate(this._focused);
        },


        validator: function(/*anything*/ value, /*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to validate the text input against the regular expression.
         // tags:
         //  protected
         return (new RegExp("^(?:" + this.regExpGen(constraints) + ")"+(this.required?"":"?")+"$")).test(value) &&
          (!this.required || !this._isEmpty(value)) &&
          (this._isEmpty(value) || this.parse(value, constraints) !== undefined); // Boolean
        },


        _isValidSubset: function(){
         // summary:
         //  Returns true if the value is either already valid or could be made valid by appending characters.
         //  This is used for validation while the user [may be] still typing.
         return this.textbox.value.search(this._partialre) == 0;
        },


        isValid: function(/*Boolean*/ isFocused){
         // summary:
         //  Tests if value is valid.
         //  Can override with your own routine in a subclass.
         // tags:
         //  protected
         return this.validator(this.textbox.value, this.constraints);
        },


        _isEmpty: function(value){
         // summary:
         //  Checks for whitespace
         return (this.trim ? /^\s*$/ : /^$/).test(value); // Boolean
        },


        getErrorMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return an error message to show if appropriate
         // tags:
         //  protected
         return (this.required && this._isEmpty(this.textbox.value)) ? this.missingMessage : this.invalidMessage; // String
        },


        getPromptMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return a hint message to show when widget is first focused
         // tags:
         //  protected
         return this.promptMessage; // String
        },


        _maskValidSubsetError: true,
        validate: function(/*Boolean*/ isFocused){
         // summary:
         //  Called by oninit, onblur, and onkeypress.
         // description:
         //  Show missing or invalid messages if appropriate, and highlight textbox field.
         // tags:
         //  protected
         var message = "";
         var isValid = this.disabled || this.isValid(isFocused);
         if(isValid){ this._maskValidSubsetError = true; }
         var isEmpty = this._isEmpty(this.textbox.value);
         var isValidSubset = !isValid && isFocused && this._isValidSubset();
         this._set("state", isValid ? "" : (((((!this._hasBeenBlurred || isFocused) && isEmpty) || isValidSubset) && this._maskValidSubsetError) ? "Incomplete" : "Error"));
         dijit.setWaiState(this.focusNode, "invalid", isValid ? "false" : "true");


         if(this.state == "Error"){
          this._maskValidSubsetError = isFocused && isValidSubset; // we want the error to show up after a blur and refocus
          message = this.getErrorMessage(isFocused);
         }else if(this.state == "Incomplete"){
          message = this.getPromptMessage(isFocused); // show the prompt whenever the value is not yet complete
          this._maskValidSubsetError = !this._hasBeenBlurred || isFocused; // no Incomplete warnings while focused
         }else if(isEmpty){
          message = this.getPromptMessage(isFocused); // show the prompt whenever there's no error and no text
         }
         this.set("message", message);


         return isValid;
        },


        displayMessage: function(/*String*/ message){
         // summary:
         //  Overridable method to display validation errors/hints.
         //  By default uses a tooltip.
         // tags:
         //  extension
         dijit.hideTooltip(this.domNode);
         if(message && this._focused){
          dijit.showTooltip(message, this.domNode, this.tooltipPosition, !this.isLeftToRight());
         }
        },


        _refreshState: function(){
         // Overrides TextBox._refreshState()
         this.validate(this._focused);
         this.inherited(arguments);
    • returns
      String|Boolean
    • summary
  • dijit.form.ValidationTextBox._setConstraintsAttr

    • type
      Function
    • parameters:
      • constraints: (typeof Object)
    • source: [view]
         if(!constraints.locale && this.lang){
          constraints.locale = this.lang;
         }
         this._set("constraints", constraints);
         this._computePartialRE();
    • summary
  • dijit.form.ValidationTextBox._computePartialRE

    • type
      Function
    • source: [view]
         var p = this.regExpGen(this.constraints);
         this.regExp = p;
         var partialre = "";
         // parse the regexp and produce a new regexp that matches valid subsets
         // if the regexp is .* then there's no use in matching subsets since everything is valid
         if(p != ".*"){ this.regExp.replace(/\\.|\[\]|\[.*?[^\\]{1}\]|\{.*?\}|\(\?[=:!]|./g,
          function (re){
           switch(re.charAt(0)){
            case '{':
            case '+':
            case '?':
            case '*':
            case '^':
            case '$':
            case '|':
            case '(':
             partialre += re;
             break;
            case ")":
             partialre += "|$)";
             break;
             default:
             partialre += "(?:"+re+"|$)";
             break;
           }
          }
         );}
         try{ // this is needed for now since the above regexp parsing needs more test verification
          "".search(partialre);
         }catch(e){ // should never be here unless the original RE is bad or the parsing is bad
          partialre = this.regExp;
          console.warn('RegExp error in ' + this.declaredClass + ': ' + this.regExp);
         } // should never be here unless the original RE is bad or the parsing is bad
         this._partialre = "^(?:" + partialre + ")$";
    • summary
  • dijit.form.ValidationTextBox.postMixInProperties

    • type
      Function
    • source: [view]
         this.inherited(arguments);
         this.messages = dojo.i18n.getLocalization("dijit.form", "validate", this.lang);
         if(this.invalidMessage == "$_unset_$"){ this.invalidMessage = this.messages.invalidMessage; }
         if(!this.invalidMessage){ this.invalidMessage = this.promptMessage; }
         if(this.missingMessage == "$_unset_$"){ this.missingMessage = this.messages.missingMessage; }
         if(!this.missingMessage){ this.missingMessage = this.invalidMessage; }
         this._setConstraintsAttr(this.constraints); // this needs to happen now (and later) due to codependency on _set*Attr calls attachPoints
    • summary
  • dijit.form.ValidationTextBox._setDisabledAttr

    • type
      Function
    • parameters:
      • value: (typeof Boolean)
    • source: [view]
         this.inherited(arguments); // call FormValueWidget._setDisabledAttr()
         this._refreshState();
    • summary
  • dijit.form.ValidationTextBox._setRequiredAttr

    • type
      Function
    • parameters:
      • value: (typeof Boolean)
    • source: [view]
         this._set("required", value);
         dijit.setWaiState(this.focusNode, "required", value);
         this._refreshState();
    • summary
  • dijit.form.ValidationTextBox._setMessageAttr

    • type
      Function
    • parameters:
      • message: (typeof String)
    • source: [view]
         this._set("message", message);
         this.displayMessage(message);
    • summary
  • dijit.form.ValidationTextBox.reset

    • summary
  • dijit.form.ValidationTextBox._onBlur

    • type
      Function
    • source: [view]
      define("dijit/form/ValidationTextBox", ["dojo", "dijit", "text!dijit/form/templates/ValidationTextBox.html", "dojo/i18n", "dijit/form/TextBox", "dijit/Tooltip", "i18n!dijit/form/nls/validate"], function(dojo, dijit) {




       dijit.form.ValidationTextBox.__Constraints = function(){
        // locale: String
        //  locale used for validation, picks up value from this widget's lang attribute
        // _flags_: anything
        //  various flags passed to regExpGen function
        this.locale = "";
        this._flags_ = "";
       }




      dojo.declare(
       "dijit.form.ValidationTextBox",
       dijit.form.TextBox,
       {
        // summary:
        //  Base class for textbox widgets with the ability to validate content of various types and provide user feedback.
        // tags:
        //  protected


        templateString: dojo.cache("dijit.form", "templates/ValidationTextBox.html"),
        baseClass: "dijitTextBox dijitValidationTextBox",


        // required: Boolean
        //  User is required to enter data into this field.
        required: false,


        // promptMessage: String
        //  If defined, display this hint string immediately on focus to the textbox, if empty.
        //  Also displays if the textbox value is Incomplete (not yet valid but will be with additional input).
        //  Think of this like a tooltip that tells the user what to do, not an error message
        //  that tells the user what they've done wrong.
        //
        //  Message disappears when user starts typing.
        promptMessage: "",


        // invalidMessage: String
        //   The message to display if value is invalid.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the promptMessage instead.
        invalidMessage: "$_unset_$",


        // missingMessage: String
        //   The message to display if value is empty and the field is required.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the invalidMessage instead.
        missingMessage: "$_unset_$",


        // message: String
        //  Currently error/prompt message.
        //  When using the default tooltip implementation, this will only be
        //  displayed when the field is focused.
        message: "",


        // constraints: dijit.form.ValidationTextBox.__Constraints
        //  user-defined object needed to pass parameters to the validator functions
        constraints: {},


        // regExp: [extension protected] String
        //  regular expression string used to validate the input
        //  Do not specify both regExp and regExpGen
        regExp: ".*",


        regExpGen: function(/*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to generate regExp when dependent on constraints.
         //  Do not specify both regExp and regExpGen.
         // tags:
         //  extension protected
         return this.regExp; // String
        },


        // state: [readonly] String
        //  Shows current state (ie, validation result) of input (""=Normal, Incomplete, or Error)
        state: "",


        // tooltipPosition: String[]
        //  See description of `dijit.Tooltip.defaultPosition` for details on this parameter.
        tooltipPosition: [],


        _setValueAttr: function(){
         // summary:
         //  Hook so set('value', ...) works.
         this.inherited(arguments);
         this.validate(this._focused);
        },


        validator: function(/*anything*/ value, /*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to validate the text input against the regular expression.
         // tags:
         //  protected
         return (new RegExp("^(?:" + this.regExpGen(constraints) + ")"+(this.required?"":"?")+"$")).test(value) &&
          (!this.required || !this._isEmpty(value)) &&
          (this._isEmpty(value) || this.parse(value, constraints) !== undefined); // Boolean
        },


        _isValidSubset: function(){
         // summary:
         //  Returns true if the value is either already valid or could be made valid by appending characters.
         //  This is used for validation while the user [may be] still typing.
         return this.textbox.value.search(this._partialre) == 0;
        },


        isValid: function(/*Boolean*/ isFocused){
         // summary:
         //  Tests if value is valid.
         //  Can override with your own routine in a subclass.
         // tags:
         //  protected
         return this.validator(this.textbox.value, this.constraints);
        },


        _isEmpty: function(value){
         // summary:
         //  Checks for whitespace
         return (this.trim ? /^\s*$/ : /^$/).test(value); // Boolean
        },


        getErrorMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return an error message to show if appropriate
         // tags:
         //  protected
         return (this.required && this._isEmpty(this.textbox.value)) ? this.missingMessage : this.invalidMessage; // String
        },


        getPromptMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return a hint message to show when widget is first focused
         // tags:
         //  protected
         return this.promptMessage; // String
        },


        _maskValidSubsetError: true,
        validate: function(/*Boolean*/ isFocused){
         // summary:
         //  Called by oninit, onblur, and onkeypress.
         // description:
         //  Show missing or invalid messages if appropriate, and highlight textbox field.
         // tags:
         //  protected
         var message = "";
         var isValid = this.disabled || this.isValid(isFocused);
         if(isValid){ this._maskValidSubsetError = true; }
         var isEmpty = this._isEmpty(this.textbox.value);
         var isValidSubset = !isValid && isFocused && this._isValidSubset();
         this._set("state", isValid ? "" : (((((!this._hasBeenBlurred || isFocused) && isEmpty) || isValidSubset) && this._maskValidSubsetError) ? "Incomplete" : "Error"));
         dijit.setWaiState(this.focusNode, "invalid", isValid ? "false" : "true");


         if(this.state == "Error"){
          this._maskValidSubsetError = isFocused && isValidSubset; // we want the error to show up after a blur and refocus
          message = this.getErrorMessage(isFocused);
         }else if(this.state == "Incomplete"){
          message = this.getPromptMessage(isFocused); // show the prompt whenever the value is not yet complete
          this._maskValidSubsetError = !this._hasBeenBlurred || isFocused; // no Incomplete warnings while focused
         }else if(isEmpty){
          message = this.getPromptMessage(isFocused); // show the prompt whenever there's no error and no text
         }
         this.set("message", message);


         return isValid;
        },


        displayMessage: function(/*String*/ message){
         // summary:
         //  Overridable method to display validation errors/hints.
         //  By default uses a tooltip.
         // tags:
         //  extension
         dijit.hideTooltip(this.domNode);
         if(message && this._focused){
          dijit.showTooltip(message, this.domNode, this.tooltipPosition, !this.isLeftToRight());
         }
        },


        _refreshState: function(){
         // Overrides TextBox._refreshState()
         this.validate(this._focused);
         this.inherited(arguments);
        },


        //////////// INITIALIZATION METHODS ///////////////////////////////////////


        constructor: function(){
         this.constraints = {};
        },


        _setConstraintsAttr: function(/*Object*/ constraints){
         if(!constraints.locale && this.lang){
          constraints.locale = this.lang;
         }
         this._set("constraints", constraints);
         this._computePartialRE();
        },


        _computePartialRE: function(){
         var p = this.regExpGen(this.constraints);
         this.regExp = p;
         var partialre = "";
         // parse the regexp and produce a new regexp that matches valid subsets
         // if the regexp is .* then there's no use in matching subsets since everything is valid
         if(p != ".*"){ this.regExp.replace(/\\.|\[\]|\[.*?[^\\]{1}\]|\{.*?\}|\(\?[=:!]|./g,
          function (re){
           switch(re.charAt(0)){
            case '{':
            case '+':
            case '?':
            case '*':
            case '^':
            case '$':
            case '|':
            case '(':
             partialre += re;
             break;
            case ")":
             partialre += "|$)";
             break;
             default:
             partialre += "(?:"+re+"|$)";
             break;
           }
          }
         );}
         try{ // this is needed for now since the above regexp parsing needs more test verification
          "".search(partialre);
         }catch(e){ // should never be here unless the original RE is bad or the parsing is bad
          partialre = this.regExp;
          console.warn('RegExp error in ' + this.declaredClass + ': ' + this.regExp);
         } // should never be here unless the original RE is bad or the parsing is bad
         this._partialre = "^(?:" + partialre + ")$";
        },


        postMixInProperties: function(){
         this.inherited(arguments);
         this.messages = dojo.i18n.getLocalization("dijit.form", "validate", this.lang);
         if(this.invalidMessage == "$_unset_$"){ this.invalidMessage = this.messages.invalidMessage; }
         if(!this.invalidMessage){ this.invalidMessage = this.promptMessage; }
         if(this.missingMessage == "$_unset_$"){ this.missingMessage = this.messages.missingMessage; }
         if(!this.missingMessage){ this.missingMessage = this.invalidMessage; }
         this._setConstraintsAttr(this.constraints); // this needs to happen now (and later) due to codependency on _set*Attr calls attachPoints
        },


        _setDisabledAttr: function(/*Boolean*/ value){
         this.inherited(arguments); // call FormValueWidget._setDisabledAttr()
         this._refreshState();
        },


        _setRequiredAttr: function(/*Boolean*/ value){
         this._set("required", value);
         dijit.setWaiState(this.focusNode, "required", value);
         this._refreshState();
        },


        _setMessageAttr: function(/*String*/ message){
         this._set("message", message);
         this.displayMessage(message);
        },


        reset:function(){
         // Overrides dijit.form.TextBox.reset() by also
         // hiding errors about partial matches
         this._maskValidSubsetError = true;
         this.inherited(arguments);
        },


        _onBlur: function(){
         // the message still exists but for back-compat, and to erase the tooltip
         // (if the message is being displayed as a tooltip), call displayMessage('')
         this.displayMessage('');


         this.inherited(arguments);
    • returns
      String|Boolean
    • summary
  • dijit.form.ValidationTextBox._partialre

    • summary
  • dijit.form.ValidationTextBox.messages

    • summary
  • dijit.form.MappedTextBox

    • type
      Function
    • chains:
      • dijit.form.ValidationTextBox: (prototype)
      • dijit.form.ValidationTextBox: (call)
    • summary
      A dijit.form.ValidationTextBox subclass which provides a base class for widgets that have
      a visible formatted display value, and a serializable
      value in a hidden input field which is actually sent to the server.
    • description
      The visible display may
      be locale-dependent and interactive.  The value sent to the server is stored in a hidden
      input field which uses the `name` attribute declared by the original widget.  That value sent
      to the server is defined by the dijit.form.MappedTextBox.serialize method and is typically
      locale-neutral.
      tags:
      protected
  • dijit.form.MappedTextBox.postMixInProperties

    • type
      Function
    • source: [view]
         this.inherited(arguments);


         // we want the name attribute to go to the hidden , not the displayed ,
         // so override _FormWidget.postMixInProperties() setting of nameAttrSetting
         this.nameAttrSetting = "";
    • summary
  • dijit.form.MappedTextBox.serialize

    • type
      Function
    • parameters:
      • val: (typeof anything)
      • options: (typeof Object)
    • source: [view]
         return val.toString ? val.toString() : ""; // String
    • summary
      Overridable function used to convert the get('value') result to a canonical
      (non-localized) string.  For example, will print dates in ISO format, and
      numbers the same way as they are represented in javascript.
    • tags:
    • returns
      String
  • dijit.form.MappedTextBox.toString

    • type
      Function
    • source: [view]
         var val = this.filter(this.get('value')); // call filter in case value is nonstring and filter has been customized
         return val != null ? (typeof val == "string" ? val : this.serialize(val, this.constraints)) : ""; // String
    • summary
      Returns widget as a printable string using the widget's value
    • tags:
    • returns
      String
  • dijit.form.MappedTextBox.validate

    • type
      Function
    • source: [view]
      define("dijit/form/ValidationTextBox", ["dojo", "dijit", "text!dijit/form/templates/ValidationTextBox.html", "dojo/i18n", "dijit/form/TextBox", "dijit/Tooltip", "i18n!dijit/form/nls/validate"], function(dojo, dijit) {




       dijit.form.ValidationTextBox.__Constraints = function(){
        // locale: String
        //  locale used for validation, picks up value from this widget's lang attribute
        // _flags_: anything
        //  various flags passed to regExpGen function
        this.locale = "";
        this._flags_ = "";
       }




      dojo.declare(
       "dijit.form.ValidationTextBox",
       dijit.form.TextBox,
       {
        // summary:
        //  Base class for textbox widgets with the ability to validate content of various types and provide user feedback.
        // tags:
        //  protected


        templateString: dojo.cache("dijit.form", "templates/ValidationTextBox.html"),
        baseClass: "dijitTextBox dijitValidationTextBox",


        // required: Boolean
        //  User is required to enter data into this field.
        required: false,


        // promptMessage: String
        //  If defined, display this hint string immediately on focus to the textbox, if empty.
        //  Also displays if the textbox value is Incomplete (not yet valid but will be with additional input).
        //  Think of this like a tooltip that tells the user what to do, not an error message
        //  that tells the user what they've done wrong.
        //
        //  Message disappears when user starts typing.
        promptMessage: "",


        // invalidMessage: String
        //   The message to display if value is invalid.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the promptMessage instead.
        invalidMessage: "$_unset_$",


        // missingMessage: String
        //   The message to display if value is empty and the field is required.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the invalidMessage instead.
        missingMessage: "$_unset_$",


        // message: String
        //  Currently error/prompt message.
        //  When using the default tooltip implementation, this will only be
        //  displayed when the field is focused.
        message: "",


        // constraints: dijit.form.ValidationTextBox.__Constraints
        //  user-defined object needed to pass parameters to the validator functions
        constraints: {},


        // regExp: [extension protected] String
        //  regular expression string used to validate the input
        //  Do not specify both regExp and regExpGen
        regExp: ".*",


        regExpGen: function(/*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to generate regExp when dependent on constraints.
         //  Do not specify both regExp and regExpGen.
         // tags:
         //  extension protected
         return this.regExp; // String
        },


        // state: [readonly] String
        //  Shows current state (ie, validation result) of input (""=Normal, Incomplete, or Error)
        state: "",


        // tooltipPosition: String[]
        //  See description of `dijit.Tooltip.defaultPosition` for details on this parameter.
        tooltipPosition: [],


        _setValueAttr: function(){
         // summary:
         //  Hook so set('value', ...) works.
         this.inherited(arguments);
         this.validate(this._focused);
        },


        validator: function(/*anything*/ value, /*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to validate the text input against the regular expression.
         // tags:
         //  protected
         return (new RegExp("^(?:" + this.regExpGen(constraints) + ")"+(this.required?"":"?")+"$")).test(value) &&
          (!this.required || !this._isEmpty(value)) &&
          (this._isEmpty(value) || this.parse(value, constraints) !== undefined); // Boolean
        },


        _isValidSubset: function(){
         // summary:
         //  Returns true if the value is either already valid or could be made valid by appending characters.
         //  This is used for validation while the user [may be] still typing.
         return this.textbox.value.search(this._partialre) == 0;
        },


        isValid: function(/*Boolean*/ isFocused){
         // summary:
         //  Tests if value is valid.
         //  Can override with your own routine in a subclass.
         // tags:
         //  protected
         return this.validator(this.textbox.value, this.constraints);
        },


        _isEmpty: function(value){
         // summary:
         //  Checks for whitespace
         return (this.trim ? /^\s*$/ : /^$/).test(value); // Boolean
        },


        getErrorMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return an error message to show if appropriate
         // tags:
         //  protected
         return (this.required && this._isEmpty(this.textbox.value)) ? this.missingMessage : this.invalidMessage; // String
        },


        getPromptMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return a hint message to show when widget is first focused
         // tags:
         //  protected
         return this.promptMessage; // String
        },


        _maskValidSubsetError: true,
        validate: function(/*Boolean*/ isFocused){
         // summary:
         //  Called by oninit, onblur, and onkeypress.
         // description:
         //  Show missing or invalid messages if appropriate, and highlight textbox field.
         // tags:
         //  protected
         var message = "";
         var isValid = this.disabled || this.isValid(isFocused);
         if(isValid){ this._maskValidSubsetError = true; }
         var isEmpty = this._isEmpty(this.textbox.value);
         var isValidSubset = !isValid && isFocused && this._isValidSubset();
         this._set("state", isValid ? "" : (((((!this._hasBeenBlurred || isFocused) && isEmpty) || isValidSubset) && this._maskValidSubsetError) ? "Incomplete" : "Error"));
         dijit.setWaiState(this.focusNode, "invalid", isValid ? "false" : "true");


         if(this.state == "Error"){
          this._maskValidSubsetError = isFocused && isValidSubset; // we want the error to show up after a blur and refocus
          message = this.getErrorMessage(isFocused);
         }else if(this.state == "Incomplete"){
          message = this.getPromptMessage(isFocused); // show the prompt whenever the value is not yet complete
          this._maskValidSubsetError = !this._hasBeenBlurred || isFocused; // no Incomplete warnings while focused
         }else if(isEmpty){
          message = this.getPromptMessage(isFocused); // show the prompt whenever there's no error and no text
         }
         this.set("message", message);


         return isValid;
        },


        displayMessage: function(/*String*/ message){
         // summary:
         //  Overridable method to display validation errors/hints.
         //  By default uses a tooltip.
         // tags:
         //  extension
         dijit.hideTooltip(this.domNode);
         if(message && this._focused){
          dijit.showTooltip(message, this.domNode, this.tooltipPosition, !this.isLeftToRight());
         }
        },


        _refreshState: function(){
         // Overrides TextBox._refreshState()
         this.validate(this._focused);
         this.inherited(arguments);
        },


        //////////// INITIALIZATION METHODS ///////////////////////////////////////


        constructor: function(){
         this.constraints = {};
        },


        _setConstraintsAttr: function(/*Object*/ constraints){
         if(!constraints.locale && this.lang){
          constraints.locale = this.lang;
         }
         this._set("constraints", constraints);
         this._computePartialRE();
        },


        _computePartialRE: function(){
         var p = this.regExpGen(this.constraints);
         this.regExp = p;
         var partialre = "";
         // parse the regexp and produce a new regexp that matches valid subsets
         // if the regexp is .* then there's no use in matching subsets since everything is valid
         if(p != ".*"){ this.regExp.replace(/\\.|\[\]|\[.*?[^\\]{1}\]|\{.*?\}|\(\?[=:!]|./g,
          function (re){
           switch(re.charAt(0)){
            case '{':
            case '+':
            case '?':
            case '*':
            case '^':
            case '$':
            case '|':
            case '(':
             partialre += re;
             break;
            case ")":
             partialre += "|$)";
             break;
             default:
             partialre += "(?:"+re+"|$)";
             break;
           }
          }
         );}
         try{ // this is needed for now since the above regexp parsing needs more test verification
          "".search(partialre);
         }catch(e){ // should never be here unless the original RE is bad or the parsing is bad
          partialre = this.regExp;
          console.warn('RegExp error in ' + this.declaredClass + ': ' + this.regExp);
         } // should never be here unless the original RE is bad or the parsing is bad
         this._partialre = "^(?:" + partialre + ")$";
        },


        postMixInProperties: function(){
         this.inherited(arguments);
         this.messages = dojo.i18n.getLocalization("dijit.form", "validate", this.lang);
         if(this.invalidMessage == "$_unset_$"){ this.invalidMessage = this.messages.invalidMessage; }
         if(!this.invalidMessage){ this.invalidMessage = this.promptMessage; }
         if(this.missingMessage == "$_unset_$"){ this.missingMessage = this.messages.missingMessage; }
         if(!this.missingMessage){ this.missingMessage = this.invalidMessage; }
         this._setConstraintsAttr(this.constraints); // this needs to happen now (and later) due to codependency on _set*Attr calls attachPoints
        },


        _setDisabledAttr: function(/*Boolean*/ value){
         this.inherited(arguments); // call FormValueWidget._setDisabledAttr()
         this._refreshState();
        },


        _setRequiredAttr: function(/*Boolean*/ value){
         this._set("required", value);
         dijit.setWaiState(this.focusNode, "required", value);
         this._refreshState();
        },


        _setMessageAttr: function(/*String*/ message){
         this._set("message", message);
         this.displayMessage(message);
        },


        reset:function(){
         // Overrides dijit.form.TextBox.reset() by also
         // hiding errors about partial matches
         this._maskValidSubsetError = true;
         this.inherited(arguments);
        },


        _onBlur: function(){
         // the message still exists but for back-compat, and to erase the tooltip
         // (if the message is being displayed as a tooltip), call displayMessage('')
         this.displayMessage('');


         this.inherited(arguments);
        }
       }
      );


      dojo.declare(
       "dijit.form.MappedTextBox",
       dijit.form.ValidationTextBox,
       {
        // summary:
        //  A dijit.form.ValidationTextBox subclass which provides a base class for widgets that have
        //  a visible formatted display value, and a serializable
        //  value in a hidden input field which is actually sent to the server.
        // description:
        //  The visible display may
        //  be locale-dependent and interactive. The value sent to the server is stored in a hidden
        //  input field which uses the `name` attribute declared by the original widget. That value sent
        //  to the server is defined by the dijit.form.MappedTextBox.serialize method and is typically
        //  locale-neutral.
        // tags:
        //  protected


        postMixInProperties: function(){
         this.inherited(arguments);


         // we want the name attribute to go to the hidden , not the displayed ,
         // so override _FormWidget.postMixInProperties() setting of nameAttrSetting
         this.nameAttrSetting = "";
        },


        serialize: function(/*anything*/ val, /*Object?*/ options){
         // summary:
         //  Overridable function used to convert the get('value') result to a canonical
         //  (non-localized) string. For example, will print dates in ISO format, and
         //  numbers the same way as they are represented in javascript.
         // tags:
         //  protected extension
         return val.toString ? val.toString() : ""; // String
        },


        toString: function(){
         // summary:
         //  Returns widget as a printable string using the widget's value
         // tags:
         //  protected
         var val = this.filter(this.get('value')); // call filter in case value is nonstring and filter has been customized
         return val != null ? (typeof val == "string" ? val : this.serialize(val, this.constraints)) : ""; // String
        },


        validate: function(){
         // Overrides `dijit.form.TextBox.validate`
         this.valueNode.value = this.toString();
         return this.inherited(arguments);
    • returns
      String|Boolean
    • summary
  • dijit.form.MappedTextBox.buildRendering

    • type
      Function
    • source: [view]
      define("dijit/form/ValidationTextBox", ["dojo", "dijit", "text!dijit/form/templates/ValidationTextBox.html", "dojo/i18n", "dijit/form/TextBox", "dijit/Tooltip", "i18n!dijit/form/nls/validate"], function(dojo, dijit) {




       dijit.form.ValidationTextBox.__Constraints = function(){
        // locale: String
        //  locale used for validation, picks up value from this widget's lang attribute
        // _flags_: anything
        //  various flags passed to regExpGen function
        this.locale = "";
        this._flags_ = "";
       }




      dojo.declare(
       "dijit.form.ValidationTextBox",
       dijit.form.TextBox,
       {
        // summary:
        //  Base class for textbox widgets with the ability to validate content of various types and provide user feedback.
        // tags:
        //  protected


        templateString: dojo.cache("dijit.form", "templates/ValidationTextBox.html"),
        baseClass: "dijitTextBox dijitValidationTextBox",


        // required: Boolean
        //  User is required to enter data into this field.
        required: false,


        // promptMessage: String
        //  If defined, display this hint string immediately on focus to the textbox, if empty.
        //  Also displays if the textbox value is Incomplete (not yet valid but will be with additional input).
        //  Think of this like a tooltip that tells the user what to do, not an error message
        //  that tells the user what they've done wrong.
        //
        //  Message disappears when user starts typing.
        promptMessage: "",


        // invalidMessage: String
        //   The message to display if value is invalid.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the promptMessage instead.
        invalidMessage: "$_unset_$",


        // missingMessage: String
        //   The message to display if value is empty and the field is required.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the invalidMessage instead.
        missingMessage: "$_unset_$",


        // message: String
        //  Currently error/prompt message.
        //  When using the default tooltip implementation, this will only be
        //  displayed when the field is focused.
        message: "",


        // constraints: dijit.form.ValidationTextBox.__Constraints
        //  user-defined object needed to pass parameters to the validator functions
        constraints: {},


        // regExp: [extension protected] String
        //  regular expression string used to validate the input
        //  Do not specify both regExp and regExpGen
        regExp: ".*",


        regExpGen: function(/*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to generate regExp when dependent on constraints.
         //  Do not specify both regExp and regExpGen.
         // tags:
         //  extension protected
         return this.regExp; // String
        },


        // state: [readonly] String
        //  Shows current state (ie, validation result) of input (""=Normal, Incomplete, or Error)
        state: "",


        // tooltipPosition: String[]
        //  See description of `dijit.Tooltip.defaultPosition` for details on this parameter.
        tooltipPosition: [],


        _setValueAttr: function(){
         // summary:
         //  Hook so set('value', ...) works.
         this.inherited(arguments);
         this.validate(this._focused);
        },


        validator: function(/*anything*/ value, /*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to validate the text input against the regular expression.
         // tags:
         //  protected
         return (new RegExp("^(?:" + this.regExpGen(constraints) + ")"+(this.required?"":"?")+"$")).test(value) &&
          (!this.required || !this._isEmpty(value)) &&
          (this._isEmpty(value) || this.parse(value, constraints) !== undefined); // Boolean
        },


        _isValidSubset: function(){
         // summary:
         //  Returns true if the value is either already valid or could be made valid by appending characters.
         //  This is used for validation while the user [may be] still typing.
         return this.textbox.value.search(this._partialre) == 0;
        },


        isValid: function(/*Boolean*/ isFocused){
         // summary:
         //  Tests if value is valid.
         //  Can override with your own routine in a subclass.
         // tags:
         //  protected
         return this.validator(this.textbox.value, this.constraints);
        },


        _isEmpty: function(value){
         // summary:
         //  Checks for whitespace
         return (this.trim ? /^\s*$/ : /^$/).test(value); // Boolean
        },


        getErrorMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return an error message to show if appropriate
         // tags:
         //  protected
         return (this.required && this._isEmpty(this.textbox.value)) ? this.missingMessage : this.invalidMessage; // String
        },


        getPromptMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return a hint message to show when widget is first focused
         // tags:
         //  protected
         return this.promptMessage; // String
        },


        _maskValidSubsetError: true,
        validate: function(/*Boolean*/ isFocused){
         // summary:
         //  Called by oninit, onblur, and onkeypress.
         // description:
         //  Show missing or invalid messages if appropriate, and highlight textbox field.
         // tags:
         //  protected
         var message = "";
         var isValid = this.disabled || this.isValid(isFocused);
         if(isValid){ this._maskValidSubsetError = true; }
         var isEmpty = this._isEmpty(this.textbox.value);
         var isValidSubset = !isValid && isFocused && this._isValidSubset();
         this._set("state", isValid ? "" : (((((!this._hasBeenBlurred || isFocused) && isEmpty) || isValidSubset) && this._maskValidSubsetError) ? "Incomplete" : "Error"));
         dijit.setWaiState(this.focusNode, "invalid", isValid ? "false" : "true");


         if(this.state == "Error"){
          this._maskValidSubsetError = isFocused && isValidSubset; // we want the error to show up after a blur and refocus
          message = this.getErrorMessage(isFocused);
         }else if(this.state == "Incomplete"){
          message = this.getPromptMessage(isFocused); // show the prompt whenever the value is not yet complete
          this._maskValidSubsetError = !this._hasBeenBlurred || isFocused; // no Incomplete warnings while focused
         }else if(isEmpty){
          message = this.getPromptMessage(isFocused); // show the prompt whenever there's no error and no text
         }
         this.set("message", message);


         return isValid;
        },


        displayMessage: function(/*String*/ message){
         // summary:
         //  Overridable method to display validation errors/hints.
         //  By default uses a tooltip.
         // tags:
         //  extension
         dijit.hideTooltip(this.domNode);
         if(message && this._focused){
          dijit.showTooltip(message, this.domNode, this.tooltipPosition, !this.isLeftToRight());
         }
        },


        _refreshState: function(){
         // Overrides TextBox._refreshState()
         this.validate(this._focused);
         this.inherited(arguments);
        },


        //////////// INITIALIZATION METHODS ///////////////////////////////////////


        constructor: function(){
         this.constraints = {};
        },


        _setConstraintsAttr: function(/*Object*/ constraints){
         if(!constraints.locale && this.lang){
          constraints.locale = this.lang;
         }
         this._set("constraints", constraints);
         this._computePartialRE();
        },


        _computePartialRE: function(){
         var p = this.regExpGen(this.constraints);
         this.regExp = p;
         var partialre = "";
         // parse the regexp and produce a new regexp that matches valid subsets
         // if the regexp is .* then there's no use in matching subsets since everything is valid
         if(p != ".*"){ this.regExp.replace(/\\.|\[\]|\[.*?[^\\]{1}\]|\{.*?\}|\(\?[=:!]|./g,
          function (re){
           switch(re.charAt(0)){
            case '{':
            case '+':
            case '?':
            case '*':
            case '^':
            case '$':
            case '|':
            case '(':
             partialre += re;
             break;
            case ")":
             partialre += "|$)";
             break;
             default:
             partialre += "(?:"+re+"|$)";
             break;
           }
          }
         );}
         try{ // this is needed for now since the above regexp parsing needs more test verification
          "".search(partialre);
         }catch(e){ // should never be here unless the original RE is bad or the parsing is bad
          partialre = this.regExp;
          console.warn('RegExp error in ' + this.declaredClass + ': ' + this.regExp);
         } // should never be here unless the original RE is bad or the parsing is bad
         this._partialre = "^(?:" + partialre + ")$";
        },


        postMixInProperties: function(){
         this.inherited(arguments);
         this.messages = dojo.i18n.getLocalization("dijit.form", "validate", this.lang);
         if(this.invalidMessage == "$_unset_$"){ this.invalidMessage = this.messages.invalidMessage; }
         if(!this.invalidMessage){ this.invalidMessage = this.promptMessage; }
         if(this.missingMessage == "$_unset_$"){ this.missingMessage = this.messages.missingMessage; }
         if(!this.missingMessage){ this.missingMessage = this.invalidMessage; }
         this._setConstraintsAttr(this.constraints); // this needs to happen now (and later) due to codependency on _set*Attr calls attachPoints
        },


        _setDisabledAttr: function(/*Boolean*/ value){
         this.inherited(arguments); // call FormValueWidget._setDisabledAttr()
         this._refreshState();
        },


        _setRequiredAttr: function(/*Boolean*/ value){
         this._set("required", value);
         dijit.setWaiState(this.focusNode, "required", value);
         this._refreshState();
        },


        _setMessageAttr: function(/*String*/ message){
         this._set("message", message);
         this.displayMessage(message);
        },


        reset:function(){
         // Overrides dijit.form.TextBox.reset() by also
         // hiding errors about partial matches
         this._maskValidSubsetError = true;
         this.inherited(arguments);
        },


        _onBlur: function(){
         // the message still exists but for back-compat, and to erase the tooltip
         // (if the message is being displayed as a tooltip), call displayMessage('')
         this.displayMessage('');


         this.inherited(arguments);
        }
       }
      );


      dojo.declare(
       "dijit.form.MappedTextBox",
       dijit.form.ValidationTextBox,
       {
        // summary:
        //  A dijit.form.ValidationTextBox subclass which provides a base class for widgets that have
        //  a visible formatted display value, and a serializable
        //  value in a hidden input field which is actually sent to the server.
        // description:
        //  The visible display may
        //  be locale-dependent and interactive. The value sent to the server is stored in a hidden
        //  input field which uses the `name` attribute declared by the original widget. That value sent
        //  to the server is defined by the dijit.form.MappedTextBox.serialize method and is typically
        //  locale-neutral.
        // tags:
        //  protected


        postMixInProperties: function(){
         this.inherited(arguments);


         // we want the name attribute to go to the hidden , not the displayed ,
         // so override _FormWidget.postMixInProperties() setting of nameAttrSetting
         this.nameAttrSetting = "";
        },


        serialize: function(/*anything*/ val, /*Object?*/ options){
         // summary:
         //  Overridable function used to convert the get('value') result to a canonical
         //  (non-localized) string. For example, will print dates in ISO format, and
         //  numbers the same way as they are represented in javascript.
         // tags:
         //  protected extension
         return val.toString ? val.toString() : ""; // String
        },


        toString: function(){
         // summary:
         //  Returns widget as a printable string using the widget's value
         // tags:
         //  protected
         var val = this.filter(this.get('value')); // call filter in case value is nonstring and filter has been customized
         return val != null ? (typeof val == "string" ? val : this.serialize(val, this.constraints)) : ""; // String
        },


        validate: function(){
         // Overrides `dijit.form.TextBox.validate`
         this.valueNode.value = this.toString();
         return this.inherited(arguments);
        },


        buildRendering: function(){
         // Overrides `dijit._Templated.buildRendering`


         this.inherited(arguments);


         // Create a hidden node with the serialized value used for submit
         // (as opposed to the displayed value).
         // Passing in name as markup rather than calling dojo.create() with an attrs argument
         // to make dojo.query(input[name=...]) work on IE. (see #8660)
         this.valueNode = dojo.place("", this.textbox, "after");
    • returns
      String|Boolean
    • summary
  • dijit.form.MappedTextBox.reset

    • type
      Function
    • source: [view]
      define("dijit/form/ValidationTextBox", ["dojo", "dijit", "text!dijit/form/templates/ValidationTextBox.html", "dojo/i18n", "dijit/form/TextBox", "dijit/Tooltip", "i18n!dijit/form/nls/validate"], function(dojo, dijit) {




       dijit.form.ValidationTextBox.__Constraints = function(){
        // locale: String
        //  locale used for validation, picks up value from this widget's lang attribute
        // _flags_: anything
        //  various flags passed to regExpGen function
        this.locale = "";
        this._flags_ = "";
       }




      dojo.declare(
       "dijit.form.ValidationTextBox",
       dijit.form.TextBox,
       {
        // summary:
        //  Base class for textbox widgets with the ability to validate content of various types and provide user feedback.
        // tags:
        //  protected


        templateString: dojo.cache("dijit.form", "templates/ValidationTextBox.html"),
        baseClass: "dijitTextBox dijitValidationTextBox",


        // required: Boolean
        //  User is required to enter data into this field.
        required: false,


        // promptMessage: String
        //  If defined, display this hint string immediately on focus to the textbox, if empty.
        //  Also displays if the textbox value is Incomplete (not yet valid but will be with additional input).
        //  Think of this like a tooltip that tells the user what to do, not an error message
        //  that tells the user what they've done wrong.
        //
        //  Message disappears when user starts typing.
        promptMessage: "",


        // invalidMessage: String
        //   The message to display if value is invalid.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the promptMessage instead.
        invalidMessage: "$_unset_$",


        // missingMessage: String
        //   The message to display if value is empty and the field is required.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the invalidMessage instead.
        missingMessage: "$_unset_$",


        // message: String
        //  Currently error/prompt message.
        //  When using the default tooltip implementation, this will only be
        //  displayed when the field is focused.
        message: "",


        // constraints: dijit.form.ValidationTextBox.__Constraints
        //  user-defined object needed to pass parameters to the validator functions
        constraints: {},


        // regExp: [extension protected] String
        //  regular expression string used to validate the input
        //  Do not specify both regExp and regExpGen
        regExp: ".*",


        regExpGen: function(/*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to generate regExp when dependent on constraints.
         //  Do not specify both regExp and regExpGen.
         // tags:
         //  extension protected
         return this.regExp; // String
        },


        // state: [readonly] String
        //  Shows current state (ie, validation result) of input (""=Normal, Incomplete, or Error)
        state: "",


        // tooltipPosition: String[]
        //  See description of `dijit.Tooltip.defaultPosition` for details on this parameter.
        tooltipPosition: [],


        _setValueAttr: function(){
         // summary:
         //  Hook so set('value', ...) works.
         this.inherited(arguments);
         this.validate(this._focused);
        },


        validator: function(/*anything*/ value, /*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to validate the text input against the regular expression.
         // tags:
         //  protected
         return (new RegExp("^(?:" + this.regExpGen(constraints) + ")"+(this.required?"":"?")+"$")).test(value) &&
          (!this.required || !this._isEmpty(value)) &&
          (this._isEmpty(value) || this.parse(value, constraints) !== undefined); // Boolean
        },


        _isValidSubset: function(){
         // summary:
         //  Returns true if the value is either already valid or could be made valid by appending characters.
         //  This is used for validation while the user [may be] still typing.
         return this.textbox.value.search(this._partialre) == 0;
        },


        isValid: function(/*Boolean*/ isFocused){
         // summary:
         //  Tests if value is valid.
         //  Can override with your own routine in a subclass.
         // tags:
         //  protected
         return this.validator(this.textbox.value, this.constraints);
        },


        _isEmpty: function(value){
         // summary:
         //  Checks for whitespace
         return (this.trim ? /^\s*$/ : /^$/).test(value); // Boolean
        },


        getErrorMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return an error message to show if appropriate
         // tags:
         //  protected
         return (this.required && this._isEmpty(this.textbox.value)) ? this.missingMessage : this.invalidMessage; // String
        },


        getPromptMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return a hint message to show when widget is first focused
         // tags:
         //  protected
         return this.promptMessage; // String
        },


        _maskValidSubsetError: true,
        validate: function(/*Boolean*/ isFocused){
         // summary:
         //  Called by oninit, onblur, and onkeypress.
         // description:
         //  Show missing or invalid messages if appropriate, and highlight textbox field.
         // tags:
         //  protected
         var message = "";
         var isValid = this.disabled || this.isValid(isFocused);
         if(isValid){ this._maskValidSubsetError = true; }
         var isEmpty = this._isEmpty(this.textbox.value);
         var isValidSubset = !isValid && isFocused && this._isValidSubset();
         this._set("state", isValid ? "" : (((((!this._hasBeenBlurred || isFocused) && isEmpty) || isValidSubset) && this._maskValidSubsetError) ? "Incomplete" : "Error"));
         dijit.setWaiState(this.focusNode, "invalid", isValid ? "false" : "true");


         if(this.state == "Error"){
          this._maskValidSubsetError = isFocused && isValidSubset; // we want the error to show up after a blur and refocus
          message = this.getErrorMessage(isFocused);
         }else if(this.state == "Incomplete"){
          message = this.getPromptMessage(isFocused); // show the prompt whenever the value is not yet complete
          this._maskValidSubsetError = !this._hasBeenBlurred || isFocused; // no Incomplete warnings while focused
         }else if(isEmpty){
          message = this.getPromptMessage(isFocused); // show the prompt whenever there's no error and no text
         }
         this.set("message", message);


         return isValid;
        },


        displayMessage: function(/*String*/ message){
         // summary:
         //  Overridable method to display validation errors/hints.
         //  By default uses a tooltip.
         // tags:
         //  extension
         dijit.hideTooltip(this.domNode);
         if(message && this._focused){
          dijit.showTooltip(message, this.domNode, this.tooltipPosition, !this.isLeftToRight());
         }
        },


        _refreshState: function(){
         // Overrides TextBox._refreshState()
         this.validate(this._focused);
         this.inherited(arguments);
        },


        //////////// INITIALIZATION METHODS ///////////////////////////////////////


        constructor: function(){
         this.constraints = {};
        },


        _setConstraintsAttr: function(/*Object*/ constraints){
         if(!constraints.locale && this.lang){
          constraints.locale = this.lang;
         }
         this._set("constraints", constraints);
         this._computePartialRE();
        },


        _computePartialRE: function(){
         var p = this.regExpGen(this.constraints);
         this.regExp = p;
         var partialre = "";
         // parse the regexp and produce a new regexp that matches valid subsets
         // if the regexp is .* then there's no use in matching subsets since everything is valid
         if(p != ".*"){ this.regExp.replace(/\\.|\[\]|\[.*?[^\\]{1}\]|\{.*?\}|\(\?[=:!]|./g,
          function (re){
           switch(re.charAt(0)){
            case '{':
            case '+':
            case '?':
            case '*':
            case '^':
            case '$':
            case '|':
            case '(':
             partialre += re;
             break;
            case ")":
             partialre += "|$)";
             break;
             default:
             partialre += "(?:"+re+"|$)";
             break;
           }
          }
         );}
         try{ // this is needed for now since the above regexp parsing needs more test verification
          "".search(partialre);
         }catch(e){ // should never be here unless the original RE is bad or the parsing is bad
          partialre = this.regExp;
          console.warn('RegExp error in ' + this.declaredClass + ': ' + this.regExp);
         } // should never be here unless the original RE is bad or the parsing is bad
         this._partialre = "^(?:" + partialre + ")$";
        },


        postMixInProperties: function(){
         this.inherited(arguments);
         this.messages = dojo.i18n.getLocalization("dijit.form", "validate", this.lang);
         if(this.invalidMessage == "$_unset_$"){ this.invalidMessage = this.messages.invalidMessage; }
         if(!this.invalidMessage){ this.invalidMessage = this.promptMessage; }
         if(this.missingMessage == "$_unset_$"){ this.missingMessage = this.messages.missingMessage; }
         if(!this.missingMessage){ this.missingMessage = this.invalidMessage; }
         this._setConstraintsAttr(this.constraints); // this needs to happen now (and later) due to codependency on _set*Attr calls attachPoints
        },


        _setDisabledAttr: function(/*Boolean*/ value){
         this.inherited(arguments); // call FormValueWidget._setDisabledAttr()
         this._refreshState();
        },


        _setRequiredAttr: function(/*Boolean*/ value){
         this._set("required", value);
         dijit.setWaiState(this.focusNode, "required", value);
         this._refreshState();
        },


        _setMessageAttr: function(/*String*/ message){
         this._set("message", message);
         this.displayMessage(message);
        },


        reset:function(){
         // Overrides dijit.form.TextBox.reset() by also
         // hiding errors about partial matches
         this._maskValidSubsetError = true;
         this.inherited(arguments);
        },


        _onBlur: function(){
         // the message still exists but for back-compat, and to erase the tooltip
         // (if the message is being displayed as a tooltip), call displayMessage('')
         this.displayMessage('');


         this.inherited(arguments);
        }
       }
      );


      dojo.declare(
       "dijit.form.MappedTextBox",
       dijit.form.ValidationTextBox,
       {
        // summary:
        //  A dijit.form.ValidationTextBox subclass which provides a base class for widgets that have
        //  a visible formatted display value, and a serializable
        //  value in a hidden input field which is actually sent to the server.
        // description:
        //  The visible display may
        //  be locale-dependent and interactive. The value sent to the server is stored in a hidden
        //  input field which uses the `name` attribute declared by the original widget. That value sent
        //  to the server is defined by the dijit.form.MappedTextBox.serialize method and is typically
        //  locale-neutral.
        // tags:
        //  protected


        postMixInProperties: function(){
         this.inherited(arguments);


         // we want the name attribute to go to the hidden , not the displayed ,
         // so override _FormWidget.postMixInProperties() setting of nameAttrSetting
         this.nameAttrSetting = "";
        },


        serialize: function(/*anything*/ val, /*Object?*/ options){
         // summary:
         //  Overridable function used to convert the get('value') result to a canonical
         //  (non-localized) string. For example, will print dates in ISO format, and
         //  numbers the same way as they are represented in javascript.
         // tags:
         //  protected extension
         return val.toString ? val.toString() : ""; // String
        },


        toString: function(){
         // summary:
         //  Returns widget as a printable string using the widget's value
         // tags:
         //  protected
         var val = this.filter(this.get('value')); // call filter in case value is nonstring and filter has been customized
         return val != null ? (typeof val == "string" ? val : this.serialize(val, this.constraints)) : ""; // String
        },


        validate: function(){
         // Overrides `dijit.form.TextBox.validate`
         this.valueNode.value = this.toString();
         return this.inherited(arguments);
        },


        buildRendering: function(){
         // Overrides `dijit._Templated.buildRendering`


         this.inherited(arguments);


         // Create a hidden node with the serialized value used for submit
         // (as opposed to the displayed value).
         // Passing in name as markup rather than calling dojo.create() with an attrs argument
         // to make dojo.query(input[name=...]) work on IE. (see #8660)
         this.valueNode = dojo.place("", this.textbox, "after");
        },


        reset: function(){
         // Overrides `dijit.form.ValidationTextBox.reset` to
         // reset the hidden textbox value to ''
         this.valueNode.value = '';
         this.inherited(arguments);
    • returns
      String|Boolean
    • summary
  • dijit.form.MappedTextBox.nameAttrSetting

    • summary
  • dijit.form.MappedTextBox.valueNode.value

    • summary
  • dijit.form.MappedTextBox.valueNode

    • summary
  • dijit.form.RangeBoundTextBox

    • type
      Function
    • chains:
      • dijit.form.MappedTextBox: (prototype)
      • dijit.form.MappedTextBox: (call)
    • summary
      Base class for textbox form widgets which defines a range of valid values.
  • dijit.form.RangeBoundTextBox.rangeMessage

    • type
      String
    • summary
      The message to display if value is out-of-range
  • dijit.form.RangeBoundTextBox.constraints

    • type
      Object
    • summary
  • dijit.form.RangeBoundTextBox.rangeCheck

    • type
      Function
    • parameters:
      • primitive: (typeof Number)
      • constraints: (typeof dijit.form.RangeBoundTextBox.__Constraints)
    • source: [view]
         return ("min" in constraints? (this.compare(primitive,constraints.min) >= 0) : true) &&
          ("max" in constraints? (this.compare(primitive,constraints.max) <= 0) : true); // Boolean
    • summary
      Overridable function used to validate the range of the numeric input value.
    • tags:
  • dijit.form.RangeBoundTextBox.isInRange

    • type
      Function
    • parameters:
      • isFocused: (typeof Boolean)
    • source: [view]
         return this.rangeCheck(this.get('value'), this.constraints);
    • summary
      Tests if the value is in the min/max range specified in constraints
    • tags:
  • dijit.form.RangeBoundTextBox._isDefinitelyOutOfRange

    • type
      Function
    • source: [view]
         var val = this.get('value');
         var isTooLittle = false;
         var isTooMuch = false;
         if("min" in this.constraints){
          var min = this.constraints.min;
          min = this.compare(val, ((typeof min == "number") && min >= 0 && val !=0) ? 0 : min);
          isTooLittle = (typeof min == "number") && min < 0;
         }
         if("max" in this.constraints){
          var max = this.constraints.max;
          max = this.compare(val, ((typeof max != "number") || max > 0) ? max : 0);
          isTooMuch = (typeof max == "number") && max > 0;
         }
         return isTooLittle || isTooMuch;
    • summary
      Returns true if the value is out of range and will remain
      out of range even if the user types more characters
  • dijit.form.RangeBoundTextBox._isValidSubset

    • type
      Function
    • source: [view]
         return this.inherited(arguments) && !this._isDefinitelyOutOfRange();
    • summary
      Overrides `dijit.form.ValidationTextBox._isValidSubset`.
      Returns true if the input is syntactically valid, and either within
      range or could be made in range by more typing.
  • dijit.form.RangeBoundTextBox.isValid

    • type
      Function
    • parameters:
      • isFocused: (typeof Boolean)
    • source: [view]
      define("dijit/form/ValidationTextBox", ["dojo", "dijit", "text!dijit/form/templates/ValidationTextBox.html", "dojo/i18n", "dijit/form/TextBox", "dijit/Tooltip", "i18n!dijit/form/nls/validate"], function(dojo, dijit) {




       dijit.form.ValidationTextBox.__Constraints = function(){
        // locale: String
        //  locale used for validation, picks up value from this widget's lang attribute
        // _flags_: anything
        //  various flags passed to regExpGen function
        this.locale = "";
        this._flags_ = "";
       }




      dojo.declare(
       "dijit.form.ValidationTextBox",
       dijit.form.TextBox,
       {
        // summary:
        //  Base class for textbox widgets with the ability to validate content of various types and provide user feedback.
        // tags:
        //  protected


        templateString: dojo.cache("dijit.form", "templates/ValidationTextBox.html"),
        baseClass: "dijitTextBox dijitValidationTextBox",


        // required: Boolean
        //  User is required to enter data into this field.
        required: false,


        // promptMessage: String
        //  If defined, display this hint string immediately on focus to the textbox, if empty.
        //  Also displays if the textbox value is Incomplete (not yet valid but will be with additional input).
        //  Think of this like a tooltip that tells the user what to do, not an error message
        //  that tells the user what they've done wrong.
        //
        //  Message disappears when user starts typing.
        promptMessage: "",


        // invalidMessage: String
        //   The message to display if value is invalid.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the promptMessage instead.
        invalidMessage: "$_unset_$",


        // missingMessage: String
        //   The message to display if value is empty and the field is required.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the invalidMessage instead.
        missingMessage: "$_unset_$",


        // message: String
        //  Currently error/prompt message.
        //  When using the default tooltip implementation, this will only be
        //  displayed when the field is focused.
        message: "",


        // constraints: dijit.form.ValidationTextBox.__Constraints
        //  user-defined object needed to pass parameters to the validator functions
        constraints: {},


        // regExp: [extension protected] String
        //  regular expression string used to validate the input
        //  Do not specify both regExp and regExpGen
        regExp: ".*",


        regExpGen: function(/*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to generate regExp when dependent on constraints.
         //  Do not specify both regExp and regExpGen.
         // tags:
         //  extension protected
         return this.regExp; // String
        },


        // state: [readonly] String
        //  Shows current state (ie, validation result) of input (""=Normal, Incomplete, or Error)
        state: "",


        // tooltipPosition: String[]
        //  See description of `dijit.Tooltip.defaultPosition` for details on this parameter.
        tooltipPosition: [],


        _setValueAttr: function(){
         // summary:
         //  Hook so set('value', ...) works.
         this.inherited(arguments);
         this.validate(this._focused);
        },


        validator: function(/*anything*/ value, /*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to validate the text input against the regular expression.
         // tags:
         //  protected
         return (new RegExp("^(?:" + this.regExpGen(constraints) + ")"+(this.required?"":"?")+"$")).test(value) &&
          (!this.required || !this._isEmpty(value)) &&
          (this._isEmpty(value) || this.parse(value, constraints) !== undefined); // Boolean
        },


        _isValidSubset: function(){
         // summary:
         //  Returns true if the value is either already valid or could be made valid by appending characters.
         //  This is used for validation while the user [may be] still typing.
         return this.textbox.value.search(this._partialre) == 0;
        },


        isValid: function(/*Boolean*/ isFocused){
         // summary:
         //  Tests if value is valid.
         //  Can override with your own routine in a subclass.
         // tags:
         //  protected
         return this.validator(this.textbox.value, this.constraints);
        },


        _isEmpty: function(value){
         // summary:
         //  Checks for whitespace
         return (this.trim ? /^\s*$/ : /^$/).test(value); // Boolean
        },


        getErrorMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return an error message to show if appropriate
         // tags:
         //  protected
         return (this.required && this._isEmpty(this.textbox.value)) ? this.missingMessage : this.invalidMessage; // String
        },


        getPromptMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return a hint message to show when widget is first focused
         // tags:
         //  protected
         return this.promptMessage; // String
        },


        _maskValidSubsetError: true,
        validate: function(/*Boolean*/ isFocused){
         // summary:
         //  Called by oninit, onblur, and onkeypress.
         // description:
         //  Show missing or invalid messages if appropriate, and highlight textbox field.
         // tags:
         //  protected
         var message = "";
         var isValid = this.disabled || this.isValid(isFocused);
         if(isValid){ this._maskValidSubsetError = true; }
         var isEmpty = this._isEmpty(this.textbox.value);
         var isValidSubset = !isValid && isFocused && this._isValidSubset();
         this._set("state", isValid ? "" : (((((!this._hasBeenBlurred || isFocused) && isEmpty) || isValidSubset) && this._maskValidSubsetError) ? "Incomplete" : "Error"));
         dijit.setWaiState(this.focusNode, "invalid", isValid ? "false" : "true");


         if(this.state == "Error"){
          this._maskValidSubsetError = isFocused && isValidSubset; // we want the error to show up after a blur and refocus
          message = this.getErrorMessage(isFocused);
         }else if(this.state == "Incomplete"){
          message = this.getPromptMessage(isFocused); // show the prompt whenever the value is not yet complete
          this._maskValidSubsetError = !this._hasBeenBlurred || isFocused; // no Incomplete warnings while focused
         }else if(isEmpty){
          message = this.getPromptMessage(isFocused); // show the prompt whenever there's no error and no text
         }
         this.set("message", message);


         return isValid;
        },


        displayMessage: function(/*String*/ message){
         // summary:
         //  Overridable method to display validation errors/hints.
         //  By default uses a tooltip.
         // tags:
         //  extension
         dijit.hideTooltip(this.domNode);
         if(message && this._focused){
          dijit.showTooltip(message, this.domNode, this.tooltipPosition, !this.isLeftToRight());
         }
        },


        _refreshState: function(){
         // Overrides TextBox._refreshState()
         this.validate(this._focused);
         this.inherited(arguments);
        },


        //////////// INITIALIZATION METHODS ///////////////////////////////////////


        constructor: function(){
         this.constraints = {};
        },


        _setConstraintsAttr: function(/*Object*/ constraints){
         if(!constraints.locale && this.lang){
          constraints.locale = this.lang;
         }
         this._set("constraints", constraints);
         this._computePartialRE();
        },


        _computePartialRE: function(){
         var p = this.regExpGen(this.constraints);
         this.regExp = p;
         var partialre = "";
         // parse the regexp and produce a new regexp that matches valid subsets
         // if the regexp is .* then there's no use in matching subsets since everything is valid
         if(p != ".*"){ this.regExp.replace(/\\.|\[\]|\[.*?[^\\]{1}\]|\{.*?\}|\(\?[=:!]|./g,
          function (re){
           switch(re.charAt(0)){
            case '{':
            case '+':
            case '?':
            case '*':
            case '^':
            case '$':
            case '|':
            case '(':
             partialre += re;
             break;
            case ")":
             partialre += "|$)";
             break;
             default:
             partialre += "(?:"+re+"|$)";
             break;
           }
          }
         );}
         try{ // this is needed for now since the above regexp parsing needs more test verification
          "".search(partialre);
         }catch(e){ // should never be here unless the original RE is bad or the parsing is bad
          partialre = this.regExp;
          console.warn('RegExp error in ' + this.declaredClass + ': ' + this.regExp);
         } // should never be here unless the original RE is bad or the parsing is bad
         this._partialre = "^(?:" + partialre + ")$";
        },


        postMixInProperties: function(){
         this.inherited(arguments);
         this.messages = dojo.i18n.getLocalization("dijit.form", "validate", this.lang);
         if(this.invalidMessage == "$_unset_$"){ this.invalidMessage = this.messages.invalidMessage; }
         if(!this.invalidMessage){ this.invalidMessage = this.promptMessage; }
         if(this.missingMessage == "$_unset_$"){ this.missingMessage = this.messages.missingMessage; }
         if(!this.missingMessage){ this.missingMessage = this.invalidMessage; }
         this._setConstraintsAttr(this.constraints); // this needs to happen now (and later) due to codependency on _set*Attr calls attachPoints
        },


        _setDisabledAttr: function(/*Boolean*/ value){
         this.inherited(arguments); // call FormValueWidget._setDisabledAttr()
         this._refreshState();
        },


        _setRequiredAttr: function(/*Boolean*/ value){
         this._set("required", value);
         dijit.setWaiState(this.focusNode, "required", value);
         this._refreshState();
        },


        _setMessageAttr: function(/*String*/ message){
         this._set("message", message);
         this.displayMessage(message);
        },


        reset:function(){
         // Overrides dijit.form.TextBox.reset() by also
         // hiding errors about partial matches
         this._maskValidSubsetError = true;
         this.inherited(arguments);
        },


        _onBlur: function(){
         // the message still exists but for back-compat, and to erase the tooltip
         // (if the message is being displayed as a tooltip), call displayMessage('')
         this.displayMessage('');


         this.inherited(arguments);
        }
       }
      );


      dojo.declare(
       "dijit.form.MappedTextBox",
       dijit.form.ValidationTextBox,
       {
        // summary:
        //  A dijit.form.ValidationTextBox subclass which provides a base class for widgets that have
        //  a visible formatted display value, and a serializable
        //  value in a hidden input field which is actually sent to the server.
        // description:
        //  The visible display may
        //  be locale-dependent and interactive. The value sent to the server is stored in a hidden
        //  input field which uses the `name` attribute declared by the original widget. That value sent
        //  to the server is defined by the dijit.form.MappedTextBox.serialize method and is typically
        //  locale-neutral.
        // tags:
        //  protected


        postMixInProperties: function(){
         this.inherited(arguments);


         // we want the name attribute to go to the hidden , not the displayed ,
         // so override _FormWidget.postMixInProperties() setting of nameAttrSetting
         this.nameAttrSetting = "";
        },


        serialize: function(/*anything*/ val, /*Object?*/ options){
         // summary:
         //  Overridable function used to convert the get('value') result to a canonical
         //  (non-localized) string. For example, will print dates in ISO format, and
         //  numbers the same way as they are represented in javascript.
         // tags:
         //  protected extension
         return val.toString ? val.toString() : ""; // String
        },


        toString: function(){
         // summary:
         //  Returns widget as a printable string using the widget's value
         // tags:
         //  protected
         var val = this.filter(this.get('value')); // call filter in case value is nonstring and filter has been customized
         return val != null ? (typeof val == "string" ? val : this.serialize(val, this.constraints)) : ""; // String
        },


        validate: function(){
         // Overrides `dijit.form.TextBox.validate`
         this.valueNode.value = this.toString();
         return this.inherited(arguments);
        },


        buildRendering: function(){
         // Overrides `dijit._Templated.buildRendering`


         this.inherited(arguments);


         // Create a hidden node with the serialized value used for submit
         // (as opposed to the displayed value).
         // Passing in name as markup rather than calling dojo.create() with an attrs argument
         // to make dojo.query(input[name=...]) work on IE. (see #8660)
         this.valueNode = dojo.place("", this.textbox, "after");
        },


        reset: function(){
         // Overrides `dijit.form.ValidationTextBox.reset` to
         // reset the hidden textbox value to ''
         this.valueNode.value = '';
         this.inherited(arguments);
        }
       }
      );




       dijit.form.RangeBoundTextBox.__Constraints = function(){
        // min: Number
        //  Minimum signed value. Default is -Infinity
        // max: Number
        //  Maximum signed value. Default is +Infinity
        this.min = min;
        this.max = max;
       }




      dojo.declare(
       "dijit.form.RangeBoundTextBox",
       dijit.form.MappedTextBox,
       {
        // summary:
        //  Base class for textbox form widgets which defines a range of valid values.


        // rangeMessage: String
        //  The message to display if value is out-of-range
        rangeMessage: "",



        
        // constraints: dijit.form.RangeBoundTextBox.__Constraints
        constraints: {},

        


        rangeCheck: function(/*Number*/ primitive, /*dijit.form.RangeBoundTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to validate the range of the numeric input value.
         // tags:
         //  protected
         return ("min" in constraints? (this.compare(primitive,constraints.min) >= 0) : true) &&
          ("max" in constraints? (this.compare(primitive,constraints.max) <= 0) : true); // Boolean
        },


        isInRange: function(/*Boolean*/ isFocused){
         // summary:
         //  Tests if the value is in the min/max range specified in constraints
         // tags:
         //  protected
         return this.rangeCheck(this.get('value'), this.constraints);
        },


        _isDefinitelyOutOfRange: function(){
         // summary:
         //  Returns true if the value is out of range and will remain
         //  out of range even if the user types more characters
         var val = this.get('value');
         var isTooLittle = false;
         var isTooMuch = false;
         if("min" in this.constraints){
          var min = this.constraints.min;
          min = this.compare(val, ((typeof min == "number") && min >= 0 && val !=0) ? 0 : min);
          isTooLittle = (typeof min == "number") && min < 0;
         }
         if("max" in this.constraints){
          var max = this.constraints.max;
          max = this.compare(val, ((typeof max != "number") || max > 0) ? max : 0);
          isTooMuch = (typeof max == "number") && max > 0;
         }
         return isTooLittle || isTooMuch;
        },


        _isValidSubset: function(){
         // summary:
         //  Overrides `dijit.form.ValidationTextBox._isValidSubset`.
         //  Returns true if the input is syntactically valid, and either within
         //  range or could be made in range by more typing.
         return this.inherited(arguments) && !this._isDefinitelyOutOfRange();
        },


        isValid: function(/*Boolean*/ isFocused){
         // Overrides dijit.form.ValidationTextBox.isValid to check that the value is also in range.
         return this.inherited(arguments) &&
          ((this._isEmpty(this.textbox.value) && !this.required) || this.isInRange(isFocused)); // Boolean
    • returns
      String|Boolean
    • summary
  • dijit.form.RangeBoundTextBox.getErrorMessage

    • type
      Function
    • parameters:
      • isFocused: (typeof Boolean)
    • source: [view]
      define("dijit/form/ValidationTextBox", ["dojo", "dijit", "text!dijit/form/templates/ValidationTextBox.html", "dojo/i18n", "dijit/form/TextBox", "dijit/Tooltip", "i18n!dijit/form/nls/validate"], function(dojo, dijit) {




       dijit.form.ValidationTextBox.__Constraints = function(){
        // locale: String
        //  locale used for validation, picks up value from this widget's lang attribute
        // _flags_: anything
        //  various flags passed to regExpGen function
        this.locale = "";
        this._flags_ = "";
       }




      dojo.declare(
       "dijit.form.ValidationTextBox",
       dijit.form.TextBox,
       {
        // summary:
        //  Base class for textbox widgets with the ability to validate content of various types and provide user feedback.
        // tags:
        //  protected


        templateString: dojo.cache("dijit.form", "templates/ValidationTextBox.html"),
        baseClass: "dijitTextBox dijitValidationTextBox",


        // required: Boolean
        //  User is required to enter data into this field.
        required: false,


        // promptMessage: String
        //  If defined, display this hint string immediately on focus to the textbox, if empty.
        //  Also displays if the textbox value is Incomplete (not yet valid but will be with additional input).
        //  Think of this like a tooltip that tells the user what to do, not an error message
        //  that tells the user what they've done wrong.
        //
        //  Message disappears when user starts typing.
        promptMessage: "",


        // invalidMessage: String
        //   The message to display if value is invalid.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the promptMessage instead.
        invalidMessage: "$_unset_$",


        // missingMessage: String
        //   The message to display if value is empty and the field is required.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the invalidMessage instead.
        missingMessage: "$_unset_$",


        // message: String
        //  Currently error/prompt message.
        //  When using the default tooltip implementation, this will only be
        //  displayed when the field is focused.
        message: "",


        // constraints: dijit.form.ValidationTextBox.__Constraints
        //  user-defined object needed to pass parameters to the validator functions
        constraints: {},


        // regExp: [extension protected] String
        //  regular expression string used to validate the input
        //  Do not specify both regExp and regExpGen
        regExp: ".*",


        regExpGen: function(/*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to generate regExp when dependent on constraints.
         //  Do not specify both regExp and regExpGen.
         // tags:
         //  extension protected
         return this.regExp; // String
        },


        // state: [readonly] String
        //  Shows current state (ie, validation result) of input (""=Normal, Incomplete, or Error)
        state: "",


        // tooltipPosition: String[]
        //  See description of `dijit.Tooltip.defaultPosition` for details on this parameter.
        tooltipPosition: [],


        _setValueAttr: function(){
         // summary:
         //  Hook so set('value', ...) works.
         this.inherited(arguments);
         this.validate(this._focused);
        },


        validator: function(/*anything*/ value, /*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to validate the text input against the regular expression.
         // tags:
         //  protected
         return (new RegExp("^(?:" + this.regExpGen(constraints) + ")"+(this.required?"":"?")+"$")).test(value) &&
          (!this.required || !this._isEmpty(value)) &&
          (this._isEmpty(value) || this.parse(value, constraints) !== undefined); // Boolean
        },


        _isValidSubset: function(){
         // summary:
         //  Returns true if the value is either already valid or could be made valid by appending characters.
         //  This is used for validation while the user [may be] still typing.
         return this.textbox.value.search(this._partialre) == 0;
        },


        isValid: function(/*Boolean*/ isFocused){
         // summary:
         //  Tests if value is valid.
         //  Can override with your own routine in a subclass.
         // tags:
         //  protected
         return this.validator(this.textbox.value, this.constraints);
        },


        _isEmpty: function(value){
         // summary:
         //  Checks for whitespace
         return (this.trim ? /^\s*$/ : /^$/).test(value); // Boolean
        },


        getErrorMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return an error message to show if appropriate
         // tags:
         //  protected
         return (this.required && this._isEmpty(this.textbox.value)) ? this.missingMessage : this.invalidMessage; // String
        },


        getPromptMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return a hint message to show when widget is first focused
         // tags:
         //  protected
         return this.promptMessage; // String
        },


        _maskValidSubsetError: true,
        validate: function(/*Boolean*/ isFocused){
         // summary:
         //  Called by oninit, onblur, and onkeypress.
         // description:
         //  Show missing or invalid messages if appropriate, and highlight textbox field.
         // tags:
         //  protected
         var message = "";
         var isValid = this.disabled || this.isValid(isFocused);
         if(isValid){ this._maskValidSubsetError = true; }
         var isEmpty = this._isEmpty(this.textbox.value);
         var isValidSubset = !isValid && isFocused && this._isValidSubset();
         this._set("state", isValid ? "" : (((((!this._hasBeenBlurred || isFocused) && isEmpty) || isValidSubset) && this._maskValidSubsetError) ? "Incomplete" : "Error"));
         dijit.setWaiState(this.focusNode, "invalid", isValid ? "false" : "true");


         if(this.state == "Error"){
          this._maskValidSubsetError = isFocused && isValidSubset; // we want the error to show up after a blur and refocus
          message = this.getErrorMessage(isFocused);
         }else if(this.state == "Incomplete"){
          message = this.getPromptMessage(isFocused); // show the prompt whenever the value is not yet complete
          this._maskValidSubsetError = !this._hasBeenBlurred || isFocused; // no Incomplete warnings while focused
         }else if(isEmpty){
          message = this.getPromptMessage(isFocused); // show the prompt whenever there's no error and no text
         }
         this.set("message", message);


         return isValid;
        },


        displayMessage: function(/*String*/ message){
         // summary:
         //  Overridable method to display validation errors/hints.
         //  By default uses a tooltip.
         // tags:
         //  extension
         dijit.hideTooltip(this.domNode);
         if(message && this._focused){
          dijit.showTooltip(message, this.domNode, this.tooltipPosition, !this.isLeftToRight());
         }
        },


        _refreshState: function(){
         // Overrides TextBox._refreshState()
         this.validate(this._focused);
         this.inherited(arguments);
        },


        //////////// INITIALIZATION METHODS ///////////////////////////////////////


        constructor: function(){
         this.constraints = {};
        },


        _setConstraintsAttr: function(/*Object*/ constraints){
         if(!constraints.locale && this.lang){
          constraints.locale = this.lang;
         }
         this._set("constraints", constraints);
         this._computePartialRE();
        },


        _computePartialRE: function(){
         var p = this.regExpGen(this.constraints);
         this.regExp = p;
         var partialre = "";
         // parse the regexp and produce a new regexp that matches valid subsets
         // if the regexp is .* then there's no use in matching subsets since everything is valid
         if(p != ".*"){ this.regExp.replace(/\\.|\[\]|\[.*?[^\\]{1}\]|\{.*?\}|\(\?[=:!]|./g,
          function (re){
           switch(re.charAt(0)){
            case '{':
            case '+':
            case '?':
            case '*':
            case '^':
            case '$':
            case '|':
            case '(':
             partialre += re;
             break;
            case ")":
             partialre += "|$)";
             break;
             default:
             partialre += "(?:"+re+"|$)";
             break;
           }
          }
         );}
         try{ // this is needed for now since the above regexp parsing needs more test verification
          "".search(partialre);
         }catch(e){ // should never be here unless the original RE is bad or the parsing is bad
          partialre = this.regExp;
          console.warn('RegExp error in ' + this.declaredClass + ': ' + this.regExp);
         } // should never be here unless the original RE is bad or the parsing is bad
         this._partialre = "^(?:" + partialre + ")$";
        },


        postMixInProperties: function(){
         this.inherited(arguments);
         this.messages = dojo.i18n.getLocalization("dijit.form", "validate", this.lang);
         if(this.invalidMessage == "$_unset_$"){ this.invalidMessage = this.messages.invalidMessage; }
         if(!this.invalidMessage){ this.invalidMessage = this.promptMessage; }
         if(this.missingMessage == "$_unset_$"){ this.missingMessage = this.messages.missingMessage; }
         if(!this.missingMessage){ this.missingMessage = this.invalidMessage; }
         this._setConstraintsAttr(this.constraints); // this needs to happen now (and later) due to codependency on _set*Attr calls attachPoints
        },


        _setDisabledAttr: function(/*Boolean*/ value){
         this.inherited(arguments); // call FormValueWidget._setDisabledAttr()
         this._refreshState();
        },


        _setRequiredAttr: function(/*Boolean*/ value){
         this._set("required", value);
         dijit.setWaiState(this.focusNode, "required", value);
         this._refreshState();
        },


        _setMessageAttr: function(/*String*/ message){
         this._set("message", message);
         this.displayMessage(message);
        },


        reset:function(){
         // Overrides dijit.form.TextBox.reset() by also
         // hiding errors about partial matches
         this._maskValidSubsetError = true;
         this.inherited(arguments);
        },


        _onBlur: function(){
         // the message still exists but for back-compat, and to erase the tooltip
         // (if the message is being displayed as a tooltip), call displayMessage('')
         this.displayMessage('');


         this.inherited(arguments);
        }
       }
      );


      dojo.declare(
       "dijit.form.MappedTextBox",
       dijit.form.ValidationTextBox,
       {
        // summary:
        //  A dijit.form.ValidationTextBox subclass which provides a base class for widgets that have
        //  a visible formatted display value, and a serializable
        //  value in a hidden input field which is actually sent to the server.
        // description:
        //  The visible display may
        //  be locale-dependent and interactive. The value sent to the server is stored in a hidden
        //  input field which uses the `name` attribute declared by the original widget. That value sent
        //  to the server is defined by the dijit.form.MappedTextBox.serialize method and is typically
        //  locale-neutral.
        // tags:
        //  protected


        postMixInProperties: function(){
         this.inherited(arguments);


         // we want the name attribute to go to the hidden , not the displayed ,
         // so override _FormWidget.postMixInProperties() setting of nameAttrSetting
         this.nameAttrSetting = "";
        },


        serialize: function(/*anything*/ val, /*Object?*/ options){
         // summary:
         //  Overridable function used to convert the get('value') result to a canonical
         //  (non-localized) string. For example, will print dates in ISO format, and
         //  numbers the same way as they are represented in javascript.
         // tags:
         //  protected extension
         return val.toString ? val.toString() : ""; // String
        },


        toString: function(){
         // summary:
         //  Returns widget as a printable string using the widget's value
         // tags:
         //  protected
         var val = this.filter(this.get('value')); // call filter in case value is nonstring and filter has been customized
         return val != null ? (typeof val == "string" ? val : this.serialize(val, this.constraints)) : ""; // String
        },


        validate: function(){
         // Overrides `dijit.form.TextBox.validate`
         this.valueNode.value = this.toString();
         return this.inherited(arguments);
        },


        buildRendering: function(){
         // Overrides `dijit._Templated.buildRendering`


         this.inherited(arguments);


         // Create a hidden node with the serialized value used for submit
         // (as opposed to the displayed value).
         // Passing in name as markup rather than calling dojo.create() with an attrs argument
         // to make dojo.query(input[name=...]) work on IE. (see #8660)
         this.valueNode = dojo.place("", this.textbox, "after");
        },


        reset: function(){
         // Overrides `dijit.form.ValidationTextBox.reset` to
         // reset the hidden textbox value to ''
         this.valueNode.value = '';
         this.inherited(arguments);
        }
       }
      );




       dijit.form.RangeBoundTextBox.__Constraints = function(){
        // min: Number
        //  Minimum signed value. Default is -Infinity
        // max: Number
        //  Maximum signed value. Default is +Infinity
        this.min = min;
        this.max = max;
       }




      dojo.declare(
       "dijit.form.RangeBoundTextBox",
       dijit.form.MappedTextBox,
       {
        // summary:
        //  Base class for textbox form widgets which defines a range of valid values.


        // rangeMessage: String
        //  The message to display if value is out-of-range
        rangeMessage: "",



        
        // constraints: dijit.form.RangeBoundTextBox.__Constraints
        constraints: {},

        


        rangeCheck: function(/*Number*/ primitive, /*dijit.form.RangeBoundTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to validate the range of the numeric input value.
         // tags:
         //  protected
         return ("min" in constraints? (this.compare(primitive,constraints.min) >= 0) : true) &&
          ("max" in constraints? (this.compare(primitive,constraints.max) <= 0) : true); // Boolean
        },


        isInRange: function(/*Boolean*/ isFocused){
         // summary:
         //  Tests if the value is in the min/max range specified in constraints
         // tags:
         //  protected
         return this.rangeCheck(this.get('value'), this.constraints);
        },


        _isDefinitelyOutOfRange: function(){
         // summary:
         //  Returns true if the value is out of range and will remain
         //  out of range even if the user types more characters
         var val = this.get('value');
         var isTooLittle = false;
         var isTooMuch = false;
         if("min" in this.constraints){
          var min = this.constraints.min;
          min = this.compare(val, ((typeof min == "number") && min >= 0 && val !=0) ? 0 : min);
          isTooLittle = (typeof min == "number") && min < 0;
         }
         if("max" in this.constraints){
          var max = this.constraints.max;
          max = this.compare(val, ((typeof max != "number") || max > 0) ? max : 0);
          isTooMuch = (typeof max == "number") && max > 0;
         }
         return isTooLittle || isTooMuch;
        },


        _isValidSubset: function(){
         // summary:
         //  Overrides `dijit.form.ValidationTextBox._isValidSubset`.
         //  Returns true if the input is syntactically valid, and either within
         //  range or could be made in range by more typing.
         return this.inherited(arguments) && !this._isDefinitelyOutOfRange();
        },


        isValid: function(/*Boolean*/ isFocused){
         // Overrides dijit.form.ValidationTextBox.isValid to check that the value is also in range.
         return this.inherited(arguments) &&
          ((this._isEmpty(this.textbox.value) && !this.required) || this.isInRange(isFocused)); // Boolean
        },


        getErrorMessage: function(/*Boolean*/ isFocused){
         // Overrides dijit.form.ValidationTextBox.getErrorMessage to print "out of range" message if appropriate
         var v = this.get('value');
         if(v !== null && v !== '' && v !== undefined && (typeof v != "number" || !isNaN(v)) && !this.isInRange(isFocused)){ // don't check isInRange w/o a real value
          return this.rangeMessage; // String
         }
         return this.inherited(arguments);
    • returns
      String|Boolean
    • summary
  • dijit.form.RangeBoundTextBox.postMixInProperties

    • type
      Function
    • source: [view]
         this.inherited(arguments);
         if(!this.rangeMessage){
          this.messages = dojo.i18n.getLocalization("dijit.form", "validate", this.lang);
          this.rangeMessage = this.messages.rangeMessage;
         }
    • summary
  • dijit.form.RangeBoundTextBox._setConstraintsAttr

    • type
      Function
    • parameters:
      • constraints: (typeof Object)
    • source: [view]
         this.inherited(arguments);
         if(this.focusNode){ // not set when called from postMixInProperties
          if(this.constraints.min !== undefined){
           dijit.setWaiState(this.focusNode, "valuemin", this.constraints.min);
          }else{
           dijit.removeWaiState(this.focusNode, "valuemin");
          }
          if(this.constraints.max !== undefined){
           dijit.setWaiState(this.focusNode, "valuemax", this.constraints.max);
          }else{
           dijit.removeWaiState(this.focusNode, "valuemax");
          }
         }
    • summary
  • dijit.form.RangeBoundTextBox._setValueAttr

    • type
      Function
    • parameters:
      • value: (typeof Number)
      • priorityChange: (typeof Boolean)
    • source: [view]
         dijit.setWaiState(this.focusNode, "valuenow", value);
         this.inherited(arguments);
    • summary
      Hook so set('value', ...) works.
  • dijit.form.RangeBoundTextBox.messages

    • summary
  • dijit.form.ValidationTextBox.__Constraints

    • type
      Function
    • source: [view]
      define("dijit/form/ValidationTextBox", ["dojo", "dijit", "text!dijit/form/templates/ValidationTextBox.html", "dojo/i18n", "dijit/form/TextBox", "dijit/Tooltip", "i18n!dijit/form/nls/validate"], function(dojo, dijit) {




       dijit.form.ValidationTextBox.__Constraints = function(){
        // locale: String
        //  locale used for validation, picks up value from this widget's lang attribute
        // _flags_: anything
        //  various flags passed to regExpGen function
        this.locale = "";
        this._flags_ = "";
    • summary
  • dijit.form.ValidationTextBox.__Constraints.locale

    • type
      String
    • summary
      locale used for validation, picks up value from this widget's lang attribute
  • dijit.form.ValidationTextBox.__Constraints._flags_

    • type
      anything
    • summary
      various flags passed to regExpGen function
  • dijit.form.RangeBoundTextBox.__Constraints

    • type
      Function
    • source: [view]
      define("dijit/form/ValidationTextBox", ["dojo", "dijit", "text!dijit/form/templates/ValidationTextBox.html", "dojo/i18n", "dijit/form/TextBox", "dijit/Tooltip", "i18n!dijit/form/nls/validate"], function(dojo, dijit) {




       dijit.form.ValidationTextBox.__Constraints = function(){
        // locale: String
        //  locale used for validation, picks up value from this widget's lang attribute
        // _flags_: anything
        //  various flags passed to regExpGen function
        this.locale = "";
        this._flags_ = "";
       }




      dojo.declare(
       "dijit.form.ValidationTextBox",
       dijit.form.TextBox,
       {
        // summary:
        //  Base class for textbox widgets with the ability to validate content of various types and provide user feedback.
        // tags:
        //  protected


        templateString: dojo.cache("dijit.form", "templates/ValidationTextBox.html"),
        baseClass: "dijitTextBox dijitValidationTextBox",


        // required: Boolean
        //  User is required to enter data into this field.
        required: false,


        // promptMessage: String
        //  If defined, display this hint string immediately on focus to the textbox, if empty.
        //  Also displays if the textbox value is Incomplete (not yet valid but will be with additional input).
        //  Think of this like a tooltip that tells the user what to do, not an error message
        //  that tells the user what they've done wrong.
        //
        //  Message disappears when user starts typing.
        promptMessage: "",


        // invalidMessage: String
        //   The message to display if value is invalid.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the promptMessage instead.
        invalidMessage: "$_unset_$",


        // missingMessage: String
        //   The message to display if value is empty and the field is required.
        //  The translated string value is read from the message file by default.
        //   Set to "" to use the invalidMessage instead.
        missingMessage: "$_unset_$",


        // message: String
        //  Currently error/prompt message.
        //  When using the default tooltip implementation, this will only be
        //  displayed when the field is focused.
        message: "",


        // constraints: dijit.form.ValidationTextBox.__Constraints
        //  user-defined object needed to pass parameters to the validator functions
        constraints: {},


        // regExp: [extension protected] String
        //  regular expression string used to validate the input
        //  Do not specify both regExp and regExpGen
        regExp: ".*",


        regExpGen: function(/*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to generate regExp when dependent on constraints.
         //  Do not specify both regExp and regExpGen.
         // tags:
         //  extension protected
         return this.regExp; // String
        },


        // state: [readonly] String
        //  Shows current state (ie, validation result) of input (""=Normal, Incomplete, or Error)
        state: "",


        // tooltipPosition: String[]
        //  See description of `dijit.Tooltip.defaultPosition` for details on this parameter.
        tooltipPosition: [],


        _setValueAttr: function(){
         // summary:
         //  Hook so set('value', ...) works.
         this.inherited(arguments);
         this.validate(this._focused);
        },


        validator: function(/*anything*/ value, /*dijit.form.ValidationTextBox.__Constraints*/ constraints){
         // summary:
         //  Overridable function used to validate the text input against the regular expression.
         // tags:
         //  protected
         return (new RegExp("^(?:" + this.regExpGen(constraints) + ")"+(this.required?"":"?")+"$")).test(value) &&
          (!this.required || !this._isEmpty(value)) &&
          (this._isEmpty(value) || this.parse(value, constraints) !== undefined); // Boolean
        },


        _isValidSubset: function(){
         // summary:
         //  Returns true if the value is either already valid or could be made valid by appending characters.
         //  This is used for validation while the user [may be] still typing.
         return this.textbox.value.search(this._partialre) == 0;
        },


        isValid: function(/*Boolean*/ isFocused){
         // summary:
         //  Tests if value is valid.
         //  Can override with your own routine in a subclass.
         // tags:
         //  protected
         return this.validator(this.textbox.value, this.constraints);
        },


        _isEmpty: function(value){
         // summary:
         //  Checks for whitespace
         return (this.trim ? /^\s*$/ : /^$/).test(value); // Boolean
        },


        getErrorMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return an error message to show if appropriate
         // tags:
         //  protected
         return (this.required && this._isEmpty(this.textbox.value)) ? this.missingMessage : this.invalidMessage; // String
        },


        getPromptMessage: function(/*Boolean*/ isFocused){
         // summary:
         //  Return a hint message to show when widget is first focused
         // tags:
         //  protected
         return this.promptMessage; // String
        },


        _maskValidSubsetError: true,
        validate: function(/*Boolean*/ isFocused){
         // summary:
         //  Called by oninit, onblur, and onkeypress.
         // description:
         //  Show missing or invalid messages if appropriate, and highlight textbox field.
         // tags:
         //  protected
         var message = "";
         var isValid = this.disabled || this.isValid(isFocused);
         if(isValid){ this._maskValidSubsetError = true; }
         var isEmpty = this._isEmpty(this.textbox.value);
         var isValidSubset = !isValid && isFocused && this._isValidSubset();
         this._set("state", isValid ? "" : (((((!this._hasBeenBlurred || isFocused) && isEmpty) || isValidSubset) && this._maskValidSubsetError) ? "Incomplete" : "Error"));
         dijit.setWaiState(this.focusNode, "invalid", isValid ? "false" : "true");


         if(this.state == "Error"){
          this._maskValidSubsetError = isFocused && isValidSubset; // we want the error to show up after a blur and refocus
          message = this.getErrorMessage(isFocused);
         }else if(this.state == "Incomplete"){
          message = this.getPromptMessage(isFocused); // show the prompt whenever the value is not yet complete
          this._maskValidSubsetError = !this._hasBeenBlurred || isFocused; // no Incomplete warnings while focused
         }else if(isEmpty){
          message = this.getPromptMessage(isFocused); // show the prompt whenever there's no error and no text
         }
         this.set("message", message);


         return isValid;
        },


        displayMessage: function(/*String*/ message){
         // summary:
         //  Overridable method to display validation errors/hints.
         //  By default uses a tooltip.
         // tags:
         //  extension
         dijit.hideTooltip(this.domNode);
         if(message && this._focused){
          dijit.showTooltip(message, this.domNode, this.tooltipPosition, !this.isLeftToRight());
         }
        },


        _refreshState: function(){
         // Overrides TextBox._refreshState()
         this.validate(this._focused);
         this.inherited(arguments);
        },


        //////////// INITIALIZATION METHODS ///////////////////////////////////////


        constructor: function(){
         this.constraints = {};
        },


        _setConstraintsAttr: function(/*Object*/ constraints){
         if(!constraints.locale && this.lang){
          constraints.locale = this.lang;
         }
         this._set("constraints", constraints);
         this._computePartialRE();
        },


        _computePartialRE: function(){
         var p = this.regExpGen(this.constraints);
         this.regExp = p;
         var partialre = "";
         // parse the regexp and produce a new regexp that matches valid subsets
         // if the regexp is .* then there's no use in matching subsets since everything is valid
         if(p != ".*"){ this.regExp.replace(/\\.|\[\]|\[.*?[^\\]{1}\]|\{.*?\}|\(\?[=:!]|./g,
          function (re){
           switch(re.charAt(0)){
            case '{':
            case '+':
            case '?':
            case '*':
            case '^':
            case '$':
            case '|':
            case '(':
             partialre += re;
             break;
            case ")":
             partialre += "|$)";
             break;
             default:
             partialre += "(?:"+re+"|$)";
             break;
           }
          }
         );}
         try{ // this is needed for now since the above regexp parsing needs more test verification
          "".search(partialre);
         }catch(e){ // should never be here unless the original RE is bad or the parsing is bad
          partialre = this.regExp;
          console.warn('RegExp error in ' + this.declaredClass + ': ' + this.regExp);
         } // should never be here unless the original RE is bad or the parsing is bad
         this._partialre = "^(?:" + partialre + ")$";
        },


        postMixInProperties: function(){
         this.inherited(arguments);
         this.messages = dojo.i18n.getLocalization("dijit.form", "validate", this.lang);
         if(this.invalidMessage == "$_unset_$"){ this.invalidMessage = this.messages.invalidMessage; }
         if(!this.invalidMessage){ this.invalidMessage = this.promptMessage; }
         if(this.missingMessage == "$_unset_$"){ this.missingMessage = this.messages.missingMessage; }
         if(!this.missingMessage){ this.missingMessage = this.invalidMessage; }
         this._setConstraintsAttr(this.constraints); // this needs to happen now (and later) due to codependency on _set*Attr calls attachPoints
        },


        _setDisabledAttr: function(/*Boolean*/ value){
         this.inherited(arguments); // call FormValueWidget._setDisabledAttr()
         this._refreshState();
        },


        _setRequiredAttr: function(/*Boolean*/ value){
         this._set("required", value);
         dijit.setWaiState(this.focusNode, "required", value);
         this._refreshState();
        },


        _setMessageAttr: function(/*String*/ message){
         this._set("message", message);
         this.displayMessage(message);
        },


        reset:function(){
         // Overrides dijit.form.TextBox.reset() by also
         // hiding errors about partial matches
         this._maskValidSubsetError = true;
         this.inherited(arguments);
        },


        _onBlur: function(){
         // the message still exists but for back-compat, and to erase the tooltip
         // (if the message is being displayed as a tooltip), call displayMessage('')
         this.displayMessage('');


         this.inherited(arguments);
        }
       }
      );


      dojo.declare(
       "dijit.form.MappedTextBox",
       dijit.form.ValidationTextBox,
       {
        // summary:
        //  A dijit.form.ValidationTextBox subclass which provides a base class for widgets that have
        //  a visible formatted display value, and a serializable
        //  value in a hidden input field which is actually sent to the server.
        // description:
        //  The visible display may
        //  be locale-dependent and interactive. The value sent to the server is stored in a hidden
        //  input field which uses the `name` attribute declared by the original widget. That value sent
        //  to the server is defined by the dijit.form.MappedTextBox.serialize method and is typically
        //  locale-neutral.
        // tags:
        //  protected


        postMixInProperties: function(){
         this.inherited(arguments);


         // we want the name attribute to go to the hidden , not the displayed ,
         // so override _FormWidget.postMixInProperties() setting of nameAttrSetting
         this.nameAttrSetting = "";
        },


        serialize: function(/*anything*/ val, /*Object?*/ options){
         // summary:
         //  Overridable function used to convert the get('value') result to a canonical
         //  (non-localized) string. For example, will print dates in ISO format, and
         //  numbers the same way as they are represented in javascript.
         // tags:
         //  protected extension
         return val.toString ? val.toString() : ""; // String
        },


        toString: function(){
         // summary:
         //  Returns widget as a printable string using the widget's value
         // tags:
         //  protected
         var val = this.filter(this.get('value')); // call filter in case value is nonstring and filter has been customized
         return val != null ? (typeof val == "string" ? val : this.serialize(val, this.constraints)) : ""; // String
        },


        validate: function(){
         // Overrides `dijit.form.TextBox.validate`
         this.valueNode.value = this.toString();
         return this.inherited(arguments);
        },


        buildRendering: function(){
         // Overrides `dijit._Templated.buildRendering`


         this.inherited(arguments);


         // Create a hidden node with the serialized value used for submit
         // (as opposed to the displayed value).
         // Passing in name as markup rather than calling dojo.create() with an attrs argument
         // to make dojo.query(input[name=...]) work on IE. (see #8660)
         this.valueNode = dojo.place("", this.textbox, "after");
        },


        reset: function(){
         // Overrides `dijit.form.ValidationTextBox.reset` to
         // reset the hidden textbox value to ''
         this.valueNode.value = '';
         this.inherited(arguments);
        }
       }
      );




       dijit.form.RangeBoundTextBox.__Constraints = function(){
        // min: Number
        //  Minimum signed value. Default is -Infinity
        // max: Number
        //  Maximum signed value. Default is +Infinity
        this.min = min;
        this.max = max;
    • summary
  • dijit.form.RangeBoundTextBox.__Constraints.min

    • type
      Number
    • summary
      Minimum signed value.  Default is -Infinity
  • dijit.form.RangeBoundTextBox.__Constraints.max

    • type
      Number
    • summary
      Maximum signed value.  Default is +Infinity
  • dijit.form

    • type
      Object
    • summary
  • dijit

    • type
      Object
    • summary