X
Namespaces

dijit/form/TextBox.js

  • Provides:

    • dijit.form.TextBox
  • dijit.form.TextBox

    • type
      Function
    • chains:
      • dijit.form._FormValueWidget: (prototype)
      • dijit.form._FormValueWidget: (call)
    • summary
      A base class for textbox form inputs
  • dijit.form.TextBox.trim

    • type
      Boolean
    • summary
      Removes leading and trailing whitespace if true.  Default is false.
  • dijit.form.TextBox.uppercase

    • type
      Boolean
    • summary
      Converts all characters to uppercase if true.  Default is false.
  • dijit.form.TextBox.lowercase

    • type
      Boolean
    • summary
      Converts all characters to lowercase if true.  Default is false.
  • dijit.form.TextBox.propercase

    • type
      Boolean
    • summary
      Converts the first character of each word to uppercase if true.
  • dijit.form.TextBox.maxLength

    • type
      String
    • summary
      HTML INPUT tag maxLength declaration.
  • dijit.form.TextBox.selectOnClick

    • tags: const
    • type
      Boolean
    • summary
      If true, all text will be selected when focused with mouse
  • dijit.form.TextBox.placeHolder

    • type
      String
    • summary
      Defines a hint to help users fill out the input field (as defined in HTML 5).
      This should only contain plain text (no html markup).
  • dijit.form.TextBox.templateString

    • summary
  • dijit.form.TextBox._singleNodeTemplate

    • summary
  • dijit.form.TextBox._buttonInputDisabled

    • summary
  • dijit.form.TextBox.baseClass

    • summary
  • dijit.form.TextBox.attributeMap

    • summary
  • dijit.form.TextBox.postMixInProperties

    • type
      Function
    • source: [view]
         var type = this.type.toLowerCase();
         if(this.templateString && this.templateString.toLowerCase() == "input" || ((type == "hidden" || type == "file") && this.templateString == dijit.form.TextBox.prototype.templateString)){
          this.templateString = this._singleNodeTemplate;
         }
         this.inherited(arguments);
    • summary
  • dijit.form.TextBox._setPlaceHolderAttr

    • type
      Function
    • parameters:
      • v: (typeof )
    • source: [view]
         this._set("placeHolder", v);
         if(!this._phspan){
          this._attachPoints.push('_phspan');
          /* dijitInputField class gives placeHolder same padding as the input field
           * parent node already has dijitInputField class but it doesn't affect this
           * since it's position: absolute.
           */
          this._phspan = dojo.create('span',{className:'dijitPlaceHolder dijitInputField'},this.textbox,'after');
         }
         this._phspan.innerHTML="";
         this._phspan.appendChild(document.createTextNode(v));

         
         this._updatePlaceHolder();
    • summary
  • dijit.form.TextBox._updatePlaceHolder

    • type
      Function
    • source: [view]
         if(this._phspan){
          this._phspan.style.display=(this.placeHolder&&!this._focused&&!this.textbox.value)?"":"none";
         }
    • summary
  • dijit.form.TextBox._getValueAttr

    • type
      Function
    • source: [view]
         return this.parse(this.get('displayedValue'), this.constraints);
    • summary
      Hook so get('value') works as we like.
    • description
      For `dijit.form.TextBox` this basically returns the value of the <input>.
      
      For `dijit.form.MappedTextBox` subclasses, which have both
      a "displayed value" and a separate "submit value",
      This treats the "displayed value" as the master value, computing the
      submit value from it via this.parse().
  • dijit.form.TextBox._setValueAttr

    • type
      Function
    • parameters:
      • value: (typeof The)
        visual element value is also set to a corresponding,
        but not necessarily the same, value.
      • priorityChange: (typeof Boolean)
        If true, an onChange event is fired immediately instead of
        waiting for the next blur event.
      • formattedValue: (typeof String)
        If specified, used to set the visual element value,
        otherwise a computed visual value is used.
    • source: [view]
         var filteredValue;
         if(value !== undefined){
          // TODO: this is calling filter() on both the display value and the actual value.
          // I added a comment to the filter() definition about this, but it should be changed.
          filteredValue = this.filter(value);
          if(typeof formattedValue != "string"){
           if(filteredValue !== null && ((typeof filteredValue != "number") || !isNaN(filteredValue))){
            formattedValue = this.filter(this.format(filteredValue, this.constraints));
           }else{ formattedValue = ''; }
          }
         }
         if(formattedValue != null && formattedValue != undefined && ((typeof formattedValue) != "number" || !isNaN(formattedValue)) && this.textbox.value != formattedValue){
          this.textbox.value = formattedValue;
          this._set("displayedValue", this.get("displayedValue"));
         }


         this._updatePlaceHolder();


         this.inherited(arguments, [filteredValue, priorityChange]);
    • summary
      Hook so set('value', ...) works.
    • description
      Sets the value of the widget to "value" which can be of
      any type as determined by the widget.
  • dijit.form.TextBox.displayedValue

    • type
      String
    • summary
      For subclasses like ComboBox where the displayed value
      (ex: Kentucky) and the serialized value (ex: KY) are different,
      this represents the displayed value.
      
      Setting 'displayedValue' through set('displayedValue', ...)
      updates 'value', and vice-versa.  Otherwise 'value' is updated
      from 'displayedValue' periodically, like onBlur etc.
      
      TODO: move declaration to MappedTextBox?
      Problem is that ComboBox references displayedValue,
      for benefit of FilteringSelect.
  • dijit.form.TextBox.getDisplayedValue

    • type
      Function
    • source: [view]
         dojo.deprecated(this.declaredClass+"::getDisplayedValue() is deprecated. Use set('displayedValue') instead.", "", "2.0");
         return this.get('displayedValue');
    • summary
      Deprecated.  Use get('displayedValue') instead.
    • tags:
  • dijit.form.TextBox._getDisplayedValueAttr

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


      dojo.declare(
       "dijit.form.TextBox",
       dijit.form._FormValueWidget,
       {
        // summary:
        //  A base class for textbox form inputs


        // trim: Boolean
        //  Removes leading and trailing whitespace if true. Default is false.
        trim: false,


        // uppercase: Boolean
        //  Converts all characters to uppercase if true. Default is false.
        uppercase: false,


        // lowercase: Boolean
        //  Converts all characters to lowercase if true. Default is false.
        lowercase: false,


        // propercase: Boolean
        //  Converts the first character of each word to uppercase if true.
        propercase: false,


        // maxLength: String
        //  HTML INPUT tag maxLength declaration.
        maxLength: "",


        // selectOnClick: [const] Boolean
        //  If true, all text will be selected when focused with mouse
        selectOnClick: false,


        // placeHolder: String
        //  Defines a hint to help users fill out the input field (as defined in HTML 5).
        //  This should only contain plain text (no html markup).
        placeHolder: "",

        
        templateString: dojo.cache("dijit.form", "templates/TextBox.html"),
        _singleNodeTemplate: '',


        _buttonInputDisabled: dojo.isIE ? "disabled" : "", // allows IE to disallow focus, but Firefox cannot be disabled for mousedown events


        baseClass: "dijitTextBox",


        attributeMap: dojo.delegate(dijit.form._FormValueWidget.prototype.attributeMap, {
         maxLength: "focusNode"
        }),

        
        postMixInProperties: function(){
         var type = this.type.toLowerCase();
         if(this.templateString && this.templateString.toLowerCase() == "input" || ((type == "hidden" || type == "file") && this.templateString == dijit.form.TextBox.prototype.templateString)){
          this.templateString = this._singleNodeTemplate;
         }
         this.inherited(arguments);
        },


        _setPlaceHolderAttr: function(v){
         this._set("placeHolder", v);
         if(!this._phspan){
          this._attachPoints.push('_phspan');
          /* dijitInputField class gives placeHolder same padding as the input field
           * parent node already has dijitInputField class but it doesn't affect this
           * since it's position: absolute.
           */
          this._phspan = dojo.create('span',{className:'dijitPlaceHolder dijitInputField'},this.textbox,'after');
         }
         this._phspan.innerHTML="";
         this._phspan.appendChild(document.createTextNode(v));

         
         this._updatePlaceHolder();
        },

        
        _updatePlaceHolder: function(){
         if(this._phspan){
          this._phspan.style.display=(this.placeHolder&&!this._focused&&!this.textbox.value)?"":"none";
         }
        },


        _getValueAttr: function(){
         // summary:
         //  Hook so get('value') works as we like.
         // description:
         //  For `dijit.form.TextBox` this basically returns the value of the .
         //
         //  For `dijit.form.MappedTextBox` subclasses, which have both
         //  a "displayed value" and a separate "submit value",
         //  This treats the "displayed value" as the master value, computing the
         //  submit value from it via this.parse().
         return this.parse(this.get('displayedValue'), this.constraints);
        },


        _setValueAttr: function(value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
         // summary:
         //  Hook so set('value', ...) works.
         //
         // description:
         //  Sets the value of the widget to "value" which can be of
         //  any type as determined by the widget.
         //
         // value:
         //  The visual element value is also set to a corresponding,
         //  but not necessarily the same, value.
         //
         // formattedValue:
         //  If specified, used to set the visual element value,
         //  otherwise a computed visual value is used.
         //
         // priorityChange:
         //  If true, an onChange event is fired immediately instead of
         //  waiting for the next blur event.


         var filteredValue;
         if(value !== undefined){
          // TODO: this is calling filter() on both the display value and the actual value.
          // I added a comment to the filter() definition about this, but it should be changed.
          filteredValue = this.filter(value);
          if(typeof formattedValue != "string"){
           if(filteredValue !== null && ((typeof filteredValue != "number") || !isNaN(filteredValue))){
            formattedValue = this.filter(this.format(filteredValue, this.constraints));
           }else{ formattedValue = ''; }
          }
         }
         if(formattedValue != null && formattedValue != undefined && ((typeof formattedValue) != "number" || !isNaN(formattedValue)) && this.textbox.value != formattedValue){
          this.textbox.value = formattedValue;
          this._set("displayedValue", this.get("displayedValue"));
         }


         this._updatePlaceHolder();


         this.inherited(arguments, [filteredValue, priorityChange]);
        },


        // displayedValue: String
        //  For subclasses like ComboBox where the displayed value
        //  (ex: Kentucky) and the serialized value (ex: KY) are different,
        //  this represents the displayed value.
        //
        //  Setting 'displayedValue' through set('displayedValue', ...)
        //  updates 'value', and vice-versa. Otherwise 'value' is updated
        //  from 'displayedValue' periodically, like onBlur etc.
        //
        //  TODO: move declaration to MappedTextBox?
        //  Problem is that ComboBox references displayedValue,
        //  for benefit of FilteringSelect.
        displayedValue: "",


        getDisplayedValue: function(){
         // summary:
         //  Deprecated. Use get('displayedValue') instead.
         // tags:
         //  deprecated
         dojo.deprecated(this.declaredClass+"::getDisplayedValue() is deprecated. Use set('displayedValue') instead.", "", "2.0");
         return this.get('displayedValue');
        },


        _getDisplayedValueAttr: function(){
         // summary:
         //  Hook so get('displayedValue') works.
         // description:
         //  Returns the displayed value (what the user sees on the screen),
         //   after filtering (ie, trimming spaces etc.).
         //
         //  For some subclasses of TextBox (like ComboBox), the displayed value
         //  is different from the serialized value that's actually
         //  sent to the server (see dijit.form.ValidationTextBox.serialize)


         // TODO: maybe we should update this.displayedValue on every keystroke so that we don't need
         // this method
         // TODO: this isn't really the displayed value when the user is typing
         return this.filter(this.textbox.value);
    • summary
      Hook so get('displayedValue') works.
  • dijit.form.TextBox.setDisplayedValue

    • type
      Function
    • parameters:
      • value: (typeof String)
    • source: [view]
         dojo.deprecated(this.declaredClass+"::setDisplayedValue() is deprecated. Use set('displayedValue', ...) instead.", "", "2.0");
         this.set('displayedValue', value);
    • summary
      Deprecated.  Use set('displayedValue', ...) instead.
    • tags:
  • dijit.form.TextBox._setDisplayedValueAttr

    • type
      Function
    • parameters:
      • value: (typeof String)
    • source: [view]
         if(value === null || value === undefined){ value = '' }
         else if(typeof value != "string"){ value = String(value) }


         this.textbox.value = value;


         // sets the serialized value to something corresponding to specified displayedValue
         // (if possible), and also updates the textbox.value, for example converting "123"
         // to "123.00"
         this._setValueAttr(this.get('value'), undefined);


         this._set("displayedValue", this.get('displayedValue'));
    • summary
      Hook so set('displayedValue', ...) works.
    • description
      Sets the value of the visual element to the string "value".
      The widget value is also set to a corresponding,
      but not necessarily the same, value.
  • dijit.form.TextBox.format

    • type
      Function
    • parameters:
      • value: (typeof String)
      • constraints: (typeof Object)
    • source: [view]
         return ((value == null || value == undefined) ? "" : (value.toString ? value.toString() : value));
    • summary
      Replacable function to convert a value to a properly formatted string.
    • tags:
  • dijit.form.TextBox.parse

    • type
      Function
    • parameters:
      • value: (typeof String)
      • constraints: (typeof Object)
    • source: [view]
         return value; // String
    • summary
      Replacable function to convert a formatted string to a value
    • tags:
    • returns
      String
  • dijit.form.TextBox._refreshState

    • type
      Function
    • source: [view]
         // summary:
         //  After the user types some characters, etc., this method is
         //  called to check the field for validity etc. The base method
         //  in `dijit.form.TextBox` does nothing, but subclasses override.
         // tags:
         //  protected
    • summary
      After the user types some characters, etc., this method is
      called to check the field for validity etc.  The base method
      in `dijit.form.TextBox` does nothing, but subclasses override.
    • tags:
  • dijit.form.TextBox._onInput

    • type
      Function
    • parameters:
      • e: (typeof )
    • source: [view]
         if(e && e.type && /key/i.test(e.type) && e.keyCode){
          switch(e.keyCode){
           case dojo.keys.SHIFT:
           case dojo.keys.ALT:
           case dojo.keys.CTRL:
           case dojo.keys.TAB:
            return;
          }
         }
         if(this.intermediateChanges){
          var _this = this;
          // the setTimeout allows the key to post to the widget input box
          setTimeout(function(){ _this._handleOnChange(_this.get('value'), false); }, 0);
         }
         this._refreshState();


         // In case someone is watch()'ing for changes to displayedValue
         this._set("displayedValue", this.get("displayedValue"));
    • summary
  • dijit.form.TextBox.postCreate

    • type
      Function
    • source: [view]
         if(dojo.isIE){ // IE INPUT tag fontFamily has to be set directly using STYLE
          // the setTimeout gives IE a chance to render the TextBox and to deal with font inheritance
          setTimeout(dojo.hitch(this, function(){
          var s = dojo.getComputedStyle(this.domNode);
          if(s){
           var ff = s.fontFamily;
           if(ff){
            var inputs = this.domNode.getElementsByTagName("INPUT");
            if(inputs){
             for(var i=0; i < inputs.length; i++){
              inputs[i].style.fontFamily = ff;
             }
            }
           }
          }
          }), 0);
         }


         // setting the value here is needed since value="" in the template causes "undefined"
         // and setting in the DOM (instead of the JS object) helps with form reset actions
         this.textbox.setAttribute("value", this.textbox.value); // DOM and JS values should be the same


         this.inherited(arguments);


         if(dojo.isMoz || dojo.isOpera){
          this.connect(this.textbox, "oninput", "_onInput");
         }else{
          this.connect(this.textbox, "onkeydown", "_onInput");
          this.connect(this.textbox, "onkeyup", "_onInput");
          this.connect(this.textbox, "onpaste", "_onInput");
          this.connect(this.textbox, "oncut", "_onInput");
         }
    • summary
  • dijit.form.TextBox._blankValue

    • summary
  • dijit.form.TextBox.filter

    • type
      Function
    • parameters:
      • val: (typeof )
    • source: [view]
         if(val === null){ return this._blankValue; }
         if(typeof val != "string"){ return val; }
         if(this.trim){
          val = dojo.trim(val);
         }
         if(this.uppercase){
          val = val.toUpperCase();
         }
         if(this.lowercase){
          val = val.toLowerCase();
         }
         if(this.propercase){
          val = val.replace(/[^\s]+/g, function(word){
           return word.substring(0,1).toUpperCase() + word.substring(1);
          });
         }
         return val;
    • summary
      Auto-corrections (such as trimming) that are applied to textbox
      value on blur or form submit.
    • description
      For MappedTextBox subclasses, this is called twice
      - once with the display value
      - once the value as set/returned by set('value', ...)
      and get('value'), ex: a Number for NumberTextBox.
      
      In the latter case it does corrections like converting null to NaN.  In
      the former case the NumberTextBox.filter() method calls this.inherited()
      to execute standard trimming code in TextBox.filter().
      
      TODO: break this into two methods in 2.0
    • tags:
  • dijit.form.TextBox._setBlurValue

    • type
      Function
    • source: [view]
         this._setValueAttr(this.get('value'), true);
    • summary
  • dijit.form.TextBox._onBlur

    • type
      Function
    • parameters:
      • e: (typeof )
    • source: [view]
         if(this.disabled){ return; }
         this._setBlurValue();
         this.inherited(arguments);


         if(this._selectOnClickHandle){
          this.disconnect(this._selectOnClickHandle);
         }
         if(this.selectOnClick && dojo.isMoz){
          this.textbox.selectionStart = this.textbox.selectionEnd = undefined; // clear selection so that the next mouse click doesn't reselect
         }

         
         this._updatePlaceHolder();
    • summary
  • dijit.form.TextBox._onFocus

    • type
      Function
    • parameters:
      • by: (typeof String)
    • source: [view]
         if(this.disabled || this.readOnly){ return; }


         // Select all text on focus via click if nothing already selected.
         // Since mouse-up will clear the selection need to defer selection until after mouse-up.
         // Don't do anything on focus by tabbing into the widget since there's no associated mouse-up event.
         if(this.selectOnClick && by == "mouse"){
          this._selectOnClickHandle = this.connect(this.domNode, "onmouseup", function(){
           // Only select all text on first click; otherwise users would have no way to clear
           // the selection.
           this.disconnect(this._selectOnClickHandle);


           // Check if the user selected some text manually (mouse-down, mouse-move, mouse-up)
           // and if not, then select all the text
           var textIsNotSelected;
           if(dojo.isIE){
            var range = dojo.doc.selection.createRange();
            var parent = range.parentElement();
            textIsNotSelected = parent == this.textbox && range.text.length == 0;
           }else{
            textIsNotSelected = this.textbox.selectionStart == this.textbox.selectionEnd;
           }
           if(textIsNotSelected){
            dijit.selectInputText(this.textbox);
           }
          });
         }


         this._updatePlaceHolder();

         
         // call this.inherited() before refreshState(), since this.inherited() will possibly scroll the viewport
         // (to scroll the TextBox into view), which will affect how _refreshState() positions the tooltip
         this.inherited(arguments);


         this._refreshState();
    • summary
  • dijit.form.TextBox.reset

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


      dojo.declare(
       "dijit.form.TextBox",
       dijit.form._FormValueWidget,
       {
        // summary:
        //  A base class for textbox form inputs


        // trim: Boolean
        //  Removes leading and trailing whitespace if true. Default is false.
        trim: false,


        // uppercase: Boolean
        //  Converts all characters to uppercase if true. Default is false.
        uppercase: false,


        // lowercase: Boolean
        //  Converts all characters to lowercase if true. Default is false.
        lowercase: false,


        // propercase: Boolean
        //  Converts the first character of each word to uppercase if true.
        propercase: false,


        // maxLength: String
        //  HTML INPUT tag maxLength declaration.
        maxLength: "",


        // selectOnClick: [const] Boolean
        //  If true, all text will be selected when focused with mouse
        selectOnClick: false,


        // placeHolder: String
        //  Defines a hint to help users fill out the input field (as defined in HTML 5).
        //  This should only contain plain text (no html markup).
        placeHolder: "",

        
        templateString: dojo.cache("dijit.form", "templates/TextBox.html"),
        _singleNodeTemplate: '',


        _buttonInputDisabled: dojo.isIE ? "disabled" : "", // allows IE to disallow focus, but Firefox cannot be disabled for mousedown events


        baseClass: "dijitTextBox",


        attributeMap: dojo.delegate(dijit.form._FormValueWidget.prototype.attributeMap, {
         maxLength: "focusNode"
        }),

        
        postMixInProperties: function(){
         var type = this.type.toLowerCase();
         if(this.templateString && this.templateString.toLowerCase() == "input" || ((type == "hidden" || type == "file") && this.templateString == dijit.form.TextBox.prototype.templateString)){
          this.templateString = this._singleNodeTemplate;
         }
         this.inherited(arguments);
        },


        _setPlaceHolderAttr: function(v){
         this._set("placeHolder", v);
         if(!this._phspan){
          this._attachPoints.push('_phspan');
          /* dijitInputField class gives placeHolder same padding as the input field
           * parent node already has dijitInputField class but it doesn't affect this
           * since it's position: absolute.
           */
          this._phspan = dojo.create('span',{className:'dijitPlaceHolder dijitInputField'},this.textbox,'after');
         }
         this._phspan.innerHTML="";
         this._phspan.appendChild(document.createTextNode(v));

         
         this._updatePlaceHolder();
        },

        
        _updatePlaceHolder: function(){
         if(this._phspan){
          this._phspan.style.display=(this.placeHolder&&!this._focused&&!this.textbox.value)?"":"none";
         }
        },


        _getValueAttr: function(){
         // summary:
         //  Hook so get('value') works as we like.
         // description:
         //  For `dijit.form.TextBox` this basically returns the value of the .
         //
         //  For `dijit.form.MappedTextBox` subclasses, which have both
         //  a "displayed value" and a separate "submit value",
         //  This treats the "displayed value" as the master value, computing the
         //  submit value from it via this.parse().
         return this.parse(this.get('displayedValue'), this.constraints);
        },


        _setValueAttr: function(value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
         // summary:
         //  Hook so set('value', ...) works.
         //
         // description:
         //  Sets the value of the widget to "value" which can be of
         //  any type as determined by the widget.
         //
         // value:
         //  The visual element value is also set to a corresponding,
         //  but not necessarily the same, value.
         //
         // formattedValue:
         //  If specified, used to set the visual element value,
         //  otherwise a computed visual value is used.
         //
         // priorityChange:
         //  If true, an onChange event is fired immediately instead of
         //  waiting for the next blur event.


         var filteredValue;
         if(value !== undefined){
          // TODO: this is calling filter() on both the display value and the actual value.
          // I added a comment to the filter() definition about this, but it should be changed.
          filteredValue = this.filter(value);
          if(typeof formattedValue != "string"){
           if(filteredValue !== null && ((typeof filteredValue != "number") || !isNaN(filteredValue))){
            formattedValue = this.filter(this.format(filteredValue, this.constraints));
           }else{ formattedValue = ''; }
          }
         }
         if(formattedValue != null && formattedValue != undefined && ((typeof formattedValue) != "number" || !isNaN(formattedValue)) && this.textbox.value != formattedValue){
          this.textbox.value = formattedValue;
          this._set("displayedValue", this.get("displayedValue"));
         }


         this._updatePlaceHolder();


         this.inherited(arguments, [filteredValue, priorityChange]);
        },


        // displayedValue: String
        //  For subclasses like ComboBox where the displayed value
        //  (ex: Kentucky) and the serialized value (ex: KY) are different,
        //  this represents the displayed value.
        //
        //  Setting 'displayedValue' through set('displayedValue', ...)
        //  updates 'value', and vice-versa. Otherwise 'value' is updated
        //  from 'displayedValue' periodically, like onBlur etc.
        //
        //  TODO: move declaration to MappedTextBox?
        //  Problem is that ComboBox references displayedValue,
        //  for benefit of FilteringSelect.
        displayedValue: "",


        getDisplayedValue: function(){
         // summary:
         //  Deprecated. Use get('displayedValue') instead.
         // tags:
         //  deprecated
         dojo.deprecated(this.declaredClass+"::getDisplayedValue() is deprecated. Use set('displayedValue') instead.", "", "2.0");
         return this.get('displayedValue');
        },


        _getDisplayedValueAttr: function(){
         // summary:
         //  Hook so get('displayedValue') works.
         // description:
         //  Returns the displayed value (what the user sees on the screen),
         //   after filtering (ie, trimming spaces etc.).
         //
         //  For some subclasses of TextBox (like ComboBox), the displayed value
         //  is different from the serialized value that's actually
         //  sent to the server (see dijit.form.ValidationTextBox.serialize)


         // TODO: maybe we should update this.displayedValue on every keystroke so that we don't need
         // this method
         // TODO: this isn't really the displayed value when the user is typing
         return this.filter(this.textbox.value);
        },


        setDisplayedValue: function(/*String*/ value){
         // summary:
         //  Deprecated. Use set('displayedValue', ...) instead.
         // tags:
         //  deprecated
         dojo.deprecated(this.declaredClass+"::setDisplayedValue() is deprecated. Use set('displayedValue', ...) instead.", "", "2.0");
         this.set('displayedValue', value);
        },


        _setDisplayedValueAttr: function(/*String*/ value){
         // summary:
         //  Hook so set('displayedValue', ...) works.
         // description:
         //  Sets the value of the visual element to the string "value".
         //  The widget value is also set to a corresponding,
         //  but not necessarily the same, value.


         if(value === null || value === undefined){ value = '' }
         else if(typeof value != "string"){ value = String(value) }


         this.textbox.value = value;


         // sets the serialized value to something corresponding to specified displayedValue
         // (if possible), and also updates the textbox.value, for example converting "123"
         // to "123.00"
         this._setValueAttr(this.get('value'), undefined);


         this._set("displayedValue", this.get('displayedValue'));
        },


        format: function(/*String*/ value, /*Object*/ constraints){
         // summary:
         //  Replacable function to convert a value to a properly formatted string.
         // tags:
         //  protected extension
         return ((value == null || value == undefined) ? "" : (value.toString ? value.toString() : value));
        },


        parse: function(/*String*/ value, /*Object*/ constraints){
         // summary:
         //  Replacable function to convert a formatted string to a value
         // tags:
         //  protected extension


         return value; // String
        },


        _refreshState: function(){
         // summary:
         //  After the user types some characters, etc., this method is
         //  called to check the field for validity etc. The base method
         //  in `dijit.form.TextBox` does nothing, but subclasses override.
         // tags:
         //  protected
        },


        _onInput: function(e){
         if(e && e.type && /key/i.test(e.type) && e.keyCode){
          switch(e.keyCode){
           case dojo.keys.SHIFT:
           case dojo.keys.ALT:
           case dojo.keys.CTRL:
           case dojo.keys.TAB:
            return;
          }
         }
         if(this.intermediateChanges){
          var _this = this;
          // the setTimeout allows the key to post to the widget input box
          setTimeout(function(){ _this._handleOnChange(_this.get('value'), false); }, 0);
         }
         this._refreshState();


         // In case someone is watch()'ing for changes to displayedValue
         this._set("displayedValue", this.get("displayedValue"));
        },


        postCreate: function(){
         if(dojo.isIE){ // IE INPUT tag fontFamily has to be set directly using STYLE
          // the setTimeout gives IE a chance to render the TextBox and to deal with font inheritance
          setTimeout(dojo.hitch(this, function(){
          var s = dojo.getComputedStyle(this.domNode);
          if(s){
           var ff = s.fontFamily;
           if(ff){
            var inputs = this.domNode.getElementsByTagName("INPUT");
            if(inputs){
             for(var i=0; i < inputs.length; i++){
              inputs[i].style.fontFamily = ff;
             }
            }
           }
          }
          }), 0);
         }


         // setting the value here is needed since value="" in the template causes "undefined"
         // and setting in the DOM (instead of the JS object) helps with form reset actions
         this.textbox.setAttribute("value", this.textbox.value); // DOM and JS values should be the same


         this.inherited(arguments);


         if(dojo.isMoz || dojo.isOpera){
          this.connect(this.textbox, "oninput", "_onInput");
         }else{
          this.connect(this.textbox, "onkeydown", "_onInput");
          this.connect(this.textbox, "onkeyup", "_onInput");
          this.connect(this.textbox, "onpaste", "_onInput");
          this.connect(this.textbox, "oncut", "_onInput");
         }
        },


        _blankValue: '', // if the textbox is blank, what value should be reported
        filter: function(val){
         // summary:
         //  Auto-corrections (such as trimming) that are applied to textbox
         //  value on blur or form submit.
         // description:
         //  For MappedTextBox subclasses, this is called twice
         //    - once with the display value
         //   - once the value as set/returned by set('value', ...)
         //  and get('value'), ex: a Number for NumberTextBox.
         //
         //  In the latter case it does corrections like converting null to NaN. In
         //  the former case the NumberTextBox.filter() method calls this.inherited()
         //  to execute standard trimming code in TextBox.filter().
         //
         //  TODO: break this into two methods in 2.0
         //
         // tags:
         //  protected extension
         if(val === null){ return this._blankValue; }
         if(typeof val != "string"){ return val; }
         if(this.trim){
          val = dojo.trim(val);
         }
         if(this.uppercase){
          val = val.toUpperCase();
         }
         if(this.lowercase){
          val = val.toLowerCase();
         }
         if(this.propercase){
          val = val.replace(/[^\s]+/g, function(word){
           return word.substring(0,1).toUpperCase() + word.substring(1);
          });
         }
         return val;
        },


        _setBlurValue: function(){
         this._setValueAttr(this.get('value'), true);
        },


        _onBlur: function(e){
         if(this.disabled){ return; }
         this._setBlurValue();
         this.inherited(arguments);


         if(this._selectOnClickHandle){
          this.disconnect(this._selectOnClickHandle);
         }
         if(this.selectOnClick && dojo.isMoz){
          this.textbox.selectionStart = this.textbox.selectionEnd = undefined; // clear selection so that the next mouse click doesn't reselect
         }

         
         this._updatePlaceHolder();
        },


        _onFocus: function(/*String*/ by){
         if(this.disabled || this.readOnly){ return; }


         // Select all text on focus via click if nothing already selected.
         // Since mouse-up will clear the selection need to defer selection until after mouse-up.
         // Don't do anything on focus by tabbing into the widget since there's no associated mouse-up event.
         if(this.selectOnClick && by == "mouse"){
          this._selectOnClickHandle = this.connect(this.domNode, "onmouseup", function(){
           // Only select all text on first click; otherwise users would have no way to clear
           // the selection.
           this.disconnect(this._selectOnClickHandle);


           // Check if the user selected some text manually (mouse-down, mouse-move, mouse-up)
           // and if not, then select all the text
           var textIsNotSelected;
           if(dojo.isIE){
            var range = dojo.doc.selection.createRange();
            var parent = range.parentElement();
            textIsNotSelected = parent == this.textbox && range.text.length == 0;
           }else{
            textIsNotSelected = this.textbox.selectionStart == this.textbox.selectionEnd;
           }
           if(textIsNotSelected){
            dijit.selectInputText(this.textbox);
           }
          });
         }


         this._updatePlaceHolder();

         
         // call this.inherited() before refreshState(), since this.inherited() will possibly scroll the viewport
         // (to scroll the TextBox into view), which will affect how _refreshState() positions the tooltip
         this.inherited(arguments);


         this._refreshState();
        },


        reset: function(){
         // Overrides dijit._FormWidget.reset().
         // Additionally resets the displayed textbox value to ''
         this.textbox.value = '';
         this.inherited(arguments);
    • returns
      String
    • summary
  • dijit.form.TextBox._phspan

    • summary
  • dijit.form.TextBox._phspan.innerHTML

    • summary
  • dijit.form.TextBox._phspan.style.display

    • summary
  • dijit.form.TextBox.textbox.value

    • summary
  • dijit.form.TextBox.textbox.selectionStart

    • summary
  • dijit.form.TextBox._selectOnClickHandle

    • summary
  • dijit.selectInputText

    • type
      Function
    • parameters:
      • element: (typeof DomNode)
      • start: (typeof Number)
      • stop: (typeof Number)
    • source: [view]
      define("dijit/form/TextBox", ["dojo", "dijit", "text!dijit/form/templates/TextBox.html", "dijit/form/_FormWidget"], function(dojo, dijit) {


      dojo.declare(
       "dijit.form.TextBox",
       dijit.form._FormValueWidget,
       {
        // summary:
        //  A base class for textbox form inputs


        // trim: Boolean
        //  Removes leading and trailing whitespace if true. Default is false.
        trim: false,


        // uppercase: Boolean
        //  Converts all characters to uppercase if true. Default is false.
        uppercase: false,


        // lowercase: Boolean
        //  Converts all characters to lowercase if true. Default is false.
        lowercase: false,


        // propercase: Boolean
        //  Converts the first character of each word to uppercase if true.
        propercase: false,


        // maxLength: String
        //  HTML INPUT tag maxLength declaration.
        maxLength: "",


        // selectOnClick: [const] Boolean
        //  If true, all text will be selected when focused with mouse
        selectOnClick: false,


        // placeHolder: String
        //  Defines a hint to help users fill out the input field (as defined in HTML 5).
        //  This should only contain plain text (no html markup).
        placeHolder: "",

        
        templateString: dojo.cache("dijit.form", "templates/TextBox.html"),
        _singleNodeTemplate: '',


        _buttonInputDisabled: dojo.isIE ? "disabled" : "", // allows IE to disallow focus, but Firefox cannot be disabled for mousedown events


        baseClass: "dijitTextBox",


        attributeMap: dojo.delegate(dijit.form._FormValueWidget.prototype.attributeMap, {
         maxLength: "focusNode"
        }),

        
        postMixInProperties: function(){
         var type = this.type.toLowerCase();
         if(this.templateString && this.templateString.toLowerCase() == "input" || ((type == "hidden" || type == "file") && this.templateString == dijit.form.TextBox.prototype.templateString)){
          this.templateString = this._singleNodeTemplate;
         }
         this.inherited(arguments);
        },


        _setPlaceHolderAttr: function(v){
         this._set("placeHolder", v);
         if(!this._phspan){
          this._attachPoints.push('_phspan');
          /* dijitInputField class gives placeHolder same padding as the input field
           * parent node already has dijitInputField class but it doesn't affect this
           * since it's position: absolute.
           */
          this._phspan = dojo.create('span',{className:'dijitPlaceHolder dijitInputField'},this.textbox,'after');
         }
         this._phspan.innerHTML="";
         this._phspan.appendChild(document.createTextNode(v));

         
         this._updatePlaceHolder();
        },

        
        _updatePlaceHolder: function(){
         if(this._phspan){
          this._phspan.style.display=(this.placeHolder&&!this._focused&&!this.textbox.value)?"":"none";
         }
        },


        _getValueAttr: function(){
         // summary:
         //  Hook so get('value') works as we like.
         // description:
         //  For `dijit.form.TextBox` this basically returns the value of the .
         //
         //  For `dijit.form.MappedTextBox` subclasses, which have both
         //  a "displayed value" and a separate "submit value",
         //  This treats the "displayed value" as the master value, computing the
         //  submit value from it via this.parse().
         return this.parse(this.get('displayedValue'), this.constraints);
        },


        _setValueAttr: function(value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
         // summary:
         //  Hook so set('value', ...) works.
         //
         // description:
         //  Sets the value of the widget to "value" which can be of
         //  any type as determined by the widget.
         //
         // value:
         //  The visual element value is also set to a corresponding,
         //  but not necessarily the same, value.
         //
         // formattedValue:
         //  If specified, used to set the visual element value,
         //  otherwise a computed visual value is used.
         //
         // priorityChange:
         //  If true, an onChange event is fired immediately instead of
         //  waiting for the next blur event.


         var filteredValue;
         if(value !== undefined){
          // TODO: this is calling filter() on both the display value and the actual value.
          // I added a comment to the filter() definition about this, but it should be changed.
          filteredValue = this.filter(value);
          if(typeof formattedValue != "string"){
           if(filteredValue !== null && ((typeof filteredValue != "number") || !isNaN(filteredValue))){
            formattedValue = this.filter(this.format(filteredValue, this.constraints));
           }else{ formattedValue = ''; }
          }
         }
         if(formattedValue != null && formattedValue != undefined && ((typeof formattedValue) != "number" || !isNaN(formattedValue)) && this.textbox.value != formattedValue){
          this.textbox.value = formattedValue;
          this._set("displayedValue", this.get("displayedValue"));
         }


         this._updatePlaceHolder();


         this.inherited(arguments, [filteredValue, priorityChange]);
        },


        // displayedValue: String
        //  For subclasses like ComboBox where the displayed value
        //  (ex: Kentucky) and the serialized value (ex: KY) are different,
        //  this represents the displayed value.
        //
        //  Setting 'displayedValue' through set('displayedValue', ...)
        //  updates 'value', and vice-versa. Otherwise 'value' is updated
        //  from 'displayedValue' periodically, like onBlur etc.
        //
        //  TODO: move declaration to MappedTextBox?
        //  Problem is that ComboBox references displayedValue,
        //  for benefit of FilteringSelect.
        displayedValue: "",


        getDisplayedValue: function(){
         // summary:
         //  Deprecated. Use get('displayedValue') instead.
         // tags:
         //  deprecated
         dojo.deprecated(this.declaredClass+"::getDisplayedValue() is deprecated. Use set('displayedValue') instead.", "", "2.0");
         return this.get('displayedValue');
        },


        _getDisplayedValueAttr: function(){
         // summary:
         //  Hook so get('displayedValue') works.
         // description:
         //  Returns the displayed value (what the user sees on the screen),
         //   after filtering (ie, trimming spaces etc.).
         //
         //  For some subclasses of TextBox (like ComboBox), the displayed value
         //  is different from the serialized value that's actually
         //  sent to the server (see dijit.form.ValidationTextBox.serialize)


         // TODO: maybe we should update this.displayedValue on every keystroke so that we don't need
         // this method
         // TODO: this isn't really the displayed value when the user is typing
         return this.filter(this.textbox.value);
        },


        setDisplayedValue: function(/*String*/ value){
         // summary:
         //  Deprecated. Use set('displayedValue', ...) instead.
         // tags:
         //  deprecated
         dojo.deprecated(this.declaredClass+"::setDisplayedValue() is deprecated. Use set('displayedValue', ...) instead.", "", "2.0");
         this.set('displayedValue', value);
        },


        _setDisplayedValueAttr: function(/*String*/ value){
         // summary:
         //  Hook so set('displayedValue', ...) works.
         // description:
         //  Sets the value of the visual element to the string "value".
         //  The widget value is also set to a corresponding,
         //  but not necessarily the same, value.


         if(value === null || value === undefined){ value = '' }
         else if(typeof value != "string"){ value = String(value) }


         this.textbox.value = value;


         // sets the serialized value to something corresponding to specified displayedValue
         // (if possible), and also updates the textbox.value, for example converting "123"
         // to "123.00"
         this._setValueAttr(this.get('value'), undefined);


         this._set("displayedValue", this.get('displayedValue'));
        },


        format: function(/*String*/ value, /*Object*/ constraints){
         // summary:
         //  Replacable function to convert a value to a properly formatted string.
         // tags:
         //  protected extension
         return ((value == null || value == undefined) ? "" : (value.toString ? value.toString() : value));
        },


        parse: function(/*String*/ value, /*Object*/ constraints){
         // summary:
         //  Replacable function to convert a formatted string to a value
         // tags:
         //  protected extension


         return value; // String
        },


        _refreshState: function(){
         // summary:
         //  After the user types some characters, etc., this method is
         //  called to check the field for validity etc. The base method
         //  in `dijit.form.TextBox` does nothing, but subclasses override.
         // tags:
         //  protected
        },


        _onInput: function(e){
         if(e && e.type && /key/i.test(e.type) && e.keyCode){
          switch(e.keyCode){
           case dojo.keys.SHIFT:
           case dojo.keys.ALT:
           case dojo.keys.CTRL:
           case dojo.keys.TAB:
            return;
          }
         }
         if(this.intermediateChanges){
          var _this = this;
          // the setTimeout allows the key to post to the widget input box
          setTimeout(function(){ _this._handleOnChange(_this.get('value'), false); }, 0);
         }
         this._refreshState();


         // In case someone is watch()'ing for changes to displayedValue
         this._set("displayedValue", this.get("displayedValue"));
        },


        postCreate: function(){
         if(dojo.isIE){ // IE INPUT tag fontFamily has to be set directly using STYLE
          // the setTimeout gives IE a chance to render the TextBox and to deal with font inheritance
          setTimeout(dojo.hitch(this, function(){
          var s = dojo.getComputedStyle(this.domNode);
          if(s){
           var ff = s.fontFamily;
           if(ff){
            var inputs = this.domNode.getElementsByTagName("INPUT");
            if(inputs){
             for(var i=0; i < inputs.length; i++){
              inputs[i].style.fontFamily = ff;
             }
            }
           }
          }
          }), 0);
         }


         // setting the value here is needed since value="" in the template causes "undefined"
         // and setting in the DOM (instead of the JS object) helps with form reset actions
         this.textbox.setAttribute("value", this.textbox.value); // DOM and JS values should be the same


         this.inherited(arguments);


         if(dojo.isMoz || dojo.isOpera){
          this.connect(this.textbox, "oninput", "_onInput");
         }else{
          this.connect(this.textbox, "onkeydown", "_onInput");
          this.connect(this.textbox, "onkeyup", "_onInput");
          this.connect(this.textbox, "onpaste", "_onInput");
          this.connect(this.textbox, "oncut", "_onInput");
         }
        },


        _blankValue: '', // if the textbox is blank, what value should be reported
        filter: function(val){
         // summary:
         //  Auto-corrections (such as trimming) that are applied to textbox
         //  value on blur or form submit.
         // description:
         //  For MappedTextBox subclasses, this is called twice
         //    - once with the display value
         //   - once the value as set/returned by set('value', ...)
         //  and get('value'), ex: a Number for NumberTextBox.
         //
         //  In the latter case it does corrections like converting null to NaN. In
         //  the former case the NumberTextBox.filter() method calls this.inherited()
         //  to execute standard trimming code in TextBox.filter().
         //
         //  TODO: break this into two methods in 2.0
         //
         // tags:
         //  protected extension
         if(val === null){ return this._blankValue; }
         if(typeof val != "string"){ return val; }
         if(this.trim){
          val = dojo.trim(val);
         }
         if(this.uppercase){
          val = val.toUpperCase();
         }
         if(this.lowercase){
          val = val.toLowerCase();
         }
         if(this.propercase){
          val = val.replace(/[^\s]+/g, function(word){
           return word.substring(0,1).toUpperCase() + word.substring(1);
          });
         }
         return val;
        },


        _setBlurValue: function(){
         this._setValueAttr(this.get('value'), true);
        },


        _onBlur: function(e){
         if(this.disabled){ return; }
         this._setBlurValue();
         this.inherited(arguments);


         if(this._selectOnClickHandle){
          this.disconnect(this._selectOnClickHandle);
         }
         if(this.selectOnClick && dojo.isMoz){
          this.textbox.selectionStart = this.textbox.selectionEnd = undefined; // clear selection so that the next mouse click doesn't reselect
         }

         
         this._updatePlaceHolder();
        },


        _onFocus: function(/*String*/ by){
         if(this.disabled || this.readOnly){ return; }


         // Select all text on focus via click if nothing already selected.
         // Since mouse-up will clear the selection need to defer selection until after mouse-up.
         // Don't do anything on focus by tabbing into the widget since there's no associated mouse-up event.
         if(this.selectOnClick && by == "mouse"){
          this._selectOnClickHandle = this.connect(this.domNode, "onmouseup", function(){
           // Only select all text on first click; otherwise users would have no way to clear
           // the selection.
           this.disconnect(this._selectOnClickHandle);


           // Check if the user selected some text manually (mouse-down, mouse-move, mouse-up)
           // and if not, then select all the text
           var textIsNotSelected;
           if(dojo.isIE){
            var range = dojo.doc.selection.createRange();
            var parent = range.parentElement();
            textIsNotSelected = parent == this.textbox && range.text.length == 0;
           }else{
            textIsNotSelected = this.textbox.selectionStart == this.textbox.selectionEnd;
           }
           if(textIsNotSelected){
            dijit.selectInputText(this.textbox);
           }
          });
         }


         this._updatePlaceHolder();

         
         // call this.inherited() before refreshState(), since this.inherited() will possibly scroll the viewport
         // (to scroll the TextBox into view), which will affect how _refreshState() positions the tooltip
         this.inherited(arguments);


         this._refreshState();
        },


        reset: function(){
         // Overrides dijit._FormWidget.reset().
         // Additionally resets the displayed textbox value to ''
         this.textbox.value = '';
         this.inherited(arguments);
        }
       }
      );


      dijit.selectInputText = function(/*DomNode*/ element, /*Number?*/ start, /*Number?*/ stop){
       // summary:
       //  Select text in the input element argument, from start (default 0), to stop (default end).


       // TODO: use functions in _editor/selection.js?
       var _window = dojo.global;
       var _document = dojo.doc;
       element = dojo.byId(element);
       if(isNaN(start)){ start = 0; }
       if(isNaN(stop)){ stop = element.value ? element.value.length : 0; }
       dijit.focus(element);
       if(_document["selection"] && dojo.body()["createTextRange"]){ // IE
        if(element.createTextRange){
         var r = element.createTextRange();
         r.collapse(true);
         r.moveStart("character", -99999); // move to 0
         r.moveStart("character", start); // delta from 0 is the correct position
         r.moveEnd("character", stop-start);
         r.select();
        }
       }else if(_window["getSelection"]){
        if(element.setSelectionRange){
         element.setSelectionRange(start, stop);
        }
       }
    • returns
      String
    • summary
  • dijit.form

    • type
      Object
    • summary
  • dijit

    • type
      Object
    • summary