dijit/form/_DateTimeTextBox.js

  • Provides:

    • dijit.form._DateTimeTextBox
  • dijit.form._DateTimeTextBox.__Constraints

    • type
      Function
    • chains:
      • dijit.form.RangeBoundTextBox.__Constraints: (prototype)
      • dijit.form.RangeBoundTextBox.__Constraints: (call)
      • dojo.date.locale.__FormatOptions: (call)
    • mixins:
      • dojo.date.locale.__FormatOptions.prototype: (prototype)
    • summary
      Specifies both the rules on valid/invalid values (first/last date/time allowed),
      and also formatting options for how the date/time is displayed.
    • example
      To restrict to dates within 2004, displayed in a long format like "December 25, 2005":
      
      		{min:'2004-01-01',max:'2004-12-31', formatLength:'long'}
  • dijit.form._DateTimeTextBox

    • type
      Function
    • chains:
      • dijit.form.RangeBoundTextBox: (prototype)
      • dijit.form.RangeBoundTextBox: (call)
      • dijit._HasDropDown: (call)
    • mixins:
      • dijit._HasDropDown.prototype: (prototype)
    • summary
      Base class for validating, serializable, range-bound date or time text box.
    • parameters:
      • args: (typeof Object)
    • source: [view]
         var dateClass = args.datePackage ? args.datePackage + ".Date" : "Date";
         this.dateClassObj = dojo.getObject(dateClass, false);
         this.value = new this.dateClassObj("");


         this.datePackage = args.datePackage || this.datePackage;
         this.dateLocaleModule = dojo.getObject(this.datePackage + ".locale", false);
         this.regExpGen = this.dateLocaleModule.regexp;
         this._invalidDate = dijit.form._DateTimeTextBox.prototype.value.toString();
  • dijit.form._DateTimeTextBox.templateString

    • summary
  • dijit.form._DateTimeTextBox.hasDownArrow

    • tags: const
    • type
      Boolean
    • summary
      Set this textbox to display a down arrow button, to open the drop down list.
  • dijit.form._DateTimeTextBox.openOnClick

    • tags: const
    • type
      Boolean
    • summary
      Set to true to open drop down upon clicking anywhere on the textbox.
  • dijit.form._DateTimeTextBox.constraints

    • type
      Object
    • summary
  • dijit.form._DateTimeTextBox.regExpGen

    • summary
  • dijit.form._DateTimeTextBox.datePackage

    • type
      String
    • summary
      JavaScript namespace to find calendar routines.	 Uses Gregorian calendar routines
      at dojo.date, by default.
  • dijit.form._DateTimeTextBox.compare

    • type
      Function
    • parameters:
      • val1: (typeof Date)
      • val2: (typeof Date)
    • source: [view]
         var isInvalid1 = this._isInvalidDate(val1);
         var isInvalid2 = this._isInvalidDate(val2);
         return isInvalid1 ? (isInvalid2 ? 0 : -1) : (isInvalid2 ? 1 : dojo.date.compare(val1, val2, this._selector));
    • summary
  • dijit.form._DateTimeTextBox.forceWidth

    • summary
  • dijit.form._DateTimeTextBox.format

    • type
      Function
    • parameters:
      • value: (typeof Date)
      • constraints: (typeof dojo.date.locale.__FormatOptions)
    • source: [view]
         if(!value){ return ''; }
         return this.dateLocaleModule.format(value, constraints);
    • summary
      Formats the value as a Date, according to specified locale (second argument)
    • tags:
  • dijit.form._DateTimeTextBox.parse

    • type
      Function
    • parameters:
      • value: (typeof String)
      • constraints: (typeof dojo.date.locale.__FormatOptions)
    • source: [view]
         return this.dateLocaleModule.parse(value, constraints) || (this._isEmpty(value) ? null : undefined);  // Date
    • summary
      Parses as string as a Date, according to constraints
    • tags:
    • returns
      Date
  • dijit.form._DateTimeTextBox.serialize

    • type
      Function
    • parameters:
      • val: (typeof anything)
      • options: (typeof Object)
    • source: [view]
         if(val.toGregorian){
          val = val.toGregorian();
         }
         return dojo.date.stamp.toISOString(val, options);
    • summary
  • dijit.form._DateTimeTextBox.dropDownDefaultValue

    • type
      Date
    • summary
      The default value to focus in the popupClass widget when the textbox value is empty.
  • dijit.form._DateTimeTextBox.value

    • type
      Date
    • summary
      The value of this widget as a JavaScript Date object.  Use get("value") / set("value", val) to manipulate.
      When passed to the parser in markup, must be specified according to `dojo.date.stamp.fromISOString`
  • dijit.form._DateTimeTextBox._blankValue

    • summary
  • dijit.form._DateTimeTextBox.popupClass

    • tags: protected extension
    • type
      String
    • summary
      Name of the popup widget class used to select a date/time.
      Subclasses should specify this.
  • dijit.form._DateTimeTextBox._selector

    • tags: protected extension
    • type
      String
    • summary
      Specifies constraints.selector passed to dojo.date functions, should be either
      "date" or "time".
      Subclass must specify this.
  • dijit.form._DateTimeTextBox.buildRendering

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


         if(!this.hasDownArrow){
          this._buttonNode.style.display = "none";
         }


         // If openOnClick is true, we basically just want to treat the whole widget as the
         // button. We need to do that also if the actual drop down button will be hidden,
         // so that there's a mouse method for opening the drop down.
         if(this.openOnClick || !this.hasDownArrow){
          this._buttonNode = this.domNode;
          this.baseClass += " dijitComboBoxOpenOnClick";
         }
    • summary
  • dijit.form._DateTimeTextBox._setConstraintsAttr

    • type
      Function
    • parameters:
      • constraints: (typeof Object)
    • source: [view]
         constraints.selector = this._selector;
         constraints.fullYear = true; // see #5465 - always format with 4-digit years
         var fromISO = dojo.date.stamp.fromISOString;
         if(typeof constraints.min == "string"){ constraints.min = fromISO(constraints.min); }
         if(typeof constraints.max == "string"){ constraints.max = fromISO(constraints.max); }
         this.inherited(arguments);
    • summary
  • dijit.form._DateTimeTextBox._isInvalidDate

    • type
      Function
    • parameters:
      • value: (typeof Date)
    • source: [view]
         return !value || isNaN(value) || typeof value != "object" || value.toString() == this._invalidDate;
    • summary
      Runs various tests on the value, checking for invalid conditions
    • tags:
  • dijit.form._DateTimeTextBox._setValueAttr

    • type
      Function
    • parameters:
      • value: (typeof Date|String)
      • priorityChange: (typeof Boolean)
      • formattedValue: (typeof String)
    • source: [view]
         if(value !== undefined){
          if(typeof value == "string"){
           value = dojo.date.stamp.fromISOString(value);
          }
          if(this._isInvalidDate(value)){
           value = null;
          }
          if(value instanceof Date && !(this.dateClassObj instanceof Date)){
           value = new this.dateClassObj(value);
          }
         }
         this.inherited(arguments);
         if(this.dropDown){
          this.dropDown.set('value', value, false);
         }
    • summary
      Sets the date on this textbox. Note: value can be a JavaScript Date literal or a string to be parsed.
  • dijit.form._DateTimeTextBox._set

    • type
      Function
    • parameters:
      • attr: (typeof )
      • value: (typeof )
    • source: [view]
      define("dijit/form/_DateTimeTextBox", ["dojo", "dijit", "text!dijit/form/templates/DropDownBox.html", "dojo/date", "dojo/date/locale", "dojo/date/stamp", "dijit/form/ValidationTextBox", "dijit/_HasDropDown"], function(dojo, dijit) {


      new Date("X"); // workaround for #11279, new Date("") == NaN




      dojo.declare(
       "dijit.form._DateTimeTextBox.__Constraints",
       [dijit.form.RangeBoundTextBox.__Constraints, dojo.date.locale.__FormatOptions], {
       // summary:
       //  Specifies both the rules on valid/invalid values (first/last date/time allowed),
       //  and also formatting options for how the date/time is displayed.
       // example:
       //  To restrict to dates within 2004, displayed in a long format like "December 25, 2005":
       // |  {min:'2004-01-01',max:'2004-12-31', formatLength:'long'}
      });




      dojo.declare(
       "dijit.form._DateTimeTextBox",
       [ dijit.form.RangeBoundTextBox, dijit._HasDropDown ],
       {
        // summary:
        //  Base class for validating, serializable, range-bound date or time text box.


        templateString: dojo.cache("dijit.form", "templates/DropDownBox.html"),


        // hasDownArrow: [const] Boolean
        //  Set this textbox to display a down arrow button, to open the drop down list.
        hasDownArrow: true,


        // openOnClick: [const] Boolean
        //  Set to true to open drop down upon clicking anywhere on the textbox.
        openOnClick: true,



        
        // constraints: dijit.form._DateTimeTextBox.__Constraints
        //  Despite the name, this parameter specifies both constraints on the input
        //  (including starting/ending dates/times allowed) as well as
        //  formatting options like whether the date is displayed in long (ex: December 25, 2005)
        //  or short (ex: 12/25/2005) format. See `dijit.form._DateTimeTextBox.__Constraints` for details.
        constraints: {},

        


        // Override ValidationTextBox.regExpGen().... we use a reg-ex generating function rather
        // than a straight regexp to deal with locale (plus formatting options too?)
        regExpGen: dojo.date.locale.regexp,


        // datePackage: String
        //  JavaScript namespace to find calendar routines.  Uses Gregorian calendar routines
        //  at dojo.date, by default.
        datePackage: "dojo.date",


        // Override _FormWidget.compare() to work for dates/times
        compare: function(/*Date*/ val1, /*Date*/ val2){
         var isInvalid1 = this._isInvalidDate(val1);
         var isInvalid2 = this._isInvalidDate(val2);
         return isInvalid1 ? (isInvalid2 ? 0 : -1) : (isInvalid2 ? 1 : dojo.date.compare(val1, val2, this._selector));
        },


        // flag to _HasDropDown to make drop down Calendar width == width
        forceWidth: true,


        format: function(/*Date*/ value, /*dojo.date.locale.__FormatOptions*/ constraints){
         // summary:
         //  Formats the value as a Date, according to specified locale (second argument)
         // tags:
         //  protected
         if(!value){ return ''; }
         return this.dateLocaleModule.format(value, constraints);
        },


        "parse": function(/*String*/ value, /*dojo.date.locale.__FormatOptions*/ constraints){
         // summary:
         //  Parses as string as a Date, according to constraints
         // tags:
         //  protected


         return this.dateLocaleModule.parse(value, constraints) || (this._isEmpty(value) ? null : undefined);  // Date
        },


        // Overrides ValidationTextBox.serialize() to serialize a date in canonical ISO format.
        serialize: function(/*anything*/ val, /*Object?*/ options){
         if(val.toGregorian){
          val = val.toGregorian();
         }
         return dojo.date.stamp.toISOString(val, options);
        },


        // dropDownDefaultValue: Date
        //  The default value to focus in the popupClass widget when the textbox value is empty.
        dropDownDefaultValue : new Date(),


        // value: Date
        //  The value of this widget as a JavaScript Date object. Use get("value") / set("value", val) to manipulate.
        //  When passed to the parser in markup, must be specified according to `dojo.date.stamp.fromISOString`
        value: new Date(""), // value.toString()="NaN"


        _blankValue: null, // used by filter() when the textbox is blank


        // popupClass: [protected extension] String
        //  Name of the popup widget class used to select a date/time.
        //  Subclasses should specify this.
        popupClass: "", // default is no popup = text only




        // _selector: [protected extension] String
        //  Specifies constraints.selector passed to dojo.date functions, should be either
        //  "date" or "time".
        //  Subclass must specify this.
        _selector: "",


        constructor: function(/*Object*/ args){
         var dateClass = args.datePackage ? args.datePackage + ".Date" : "Date";
         this.dateClassObj = dojo.getObject(dateClass, false);
         this.value = new this.dateClassObj("");


         this.datePackage = args.datePackage || this.datePackage;
         this.dateLocaleModule = dojo.getObject(this.datePackage + ".locale", false);
         this.regExpGen = this.dateLocaleModule.regexp;
         this._invalidDate = dijit.form._DateTimeTextBox.prototype.value.toString();
        },


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


         if(!this.hasDownArrow){
          this._buttonNode.style.display = "none";
         }


         // If openOnClick is true, we basically just want to treat the whole widget as the
         // button. We need to do that also if the actual drop down button will be hidden,
         // so that there's a mouse method for opening the drop down.
         if(this.openOnClick || !this.hasDownArrow){
          this._buttonNode = this.domNode;
          this.baseClass += " dijitComboBoxOpenOnClick";
         }
        },


        _setConstraintsAttr: function(/*Object*/ constraints){
         constraints.selector = this._selector;
         constraints.fullYear = true; // see #5465 - always format with 4-digit years
         var fromISO = dojo.date.stamp.fromISOString;
         if(typeof constraints.min == "string"){ constraints.min = fromISO(constraints.min); }
         if(typeof constraints.max == "string"){ constraints.max = fromISO(constraints.max); }
         this.inherited(arguments);
        },


        _isInvalidDate: function(/*Date*/ value){
         // summary:
         //  Runs various tests on the value, checking for invalid conditions
         // tags:
         //  private
         return !value || isNaN(value) || typeof value != "object" || value.toString() == this._invalidDate;
        },


        _setValueAttr: function(/*Date|String*/ value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
         // summary:
         //  Sets the date on this textbox. Note: value can be a JavaScript Date literal or a string to be parsed.
         if(value !== undefined){
          if(typeof value == "string"){
           value = dojo.date.stamp.fromISOString(value);
          }
          if(this._isInvalidDate(value)){
           value = null;
          }
          if(value instanceof Date && !(this.dateClassObj instanceof Date)){
           value = new this.dateClassObj(value);
          }
         }
         this.inherited(arguments);
         if(this.dropDown){
          this.dropDown.set('value', value, false);
         }
        },


        _set: function(attr, value){
         // Avoid spurious watch() notifications when value is changed to new Date object w/the same value
         if(attr == "value" && this.value instanceof Date && this.compare(value, this.value) == 0){
          return;
         }
         this.inherited(arguments);
    • returns
      Date
    • summary
  • dijit.form._DateTimeTextBox._setDropDownDefaultValueAttr

    • type
      Function
    • parameters:
      • val: (typeof Date)
    • source: [view]
         if(this._isInvalidDate(val)){
          // convert null setting into today's date, since there needs to be *some* default at all times.
           val = new this.dateClassObj()
            }
         this.dropDownDefaultValue = val;
    • summary
  • dijit.form._DateTimeTextBox.openDropDown

    • type
      Function
    • parameters:
      • callback: (typeof Function)
    • source: [view]
      define("dijit/form/_DateTimeTextBox", ["dojo", "dijit", "text!dijit/form/templates/DropDownBox.html", "dojo/date", "dojo/date/locale", "dojo/date/stamp", "dijit/form/ValidationTextBox", "dijit/_HasDropDown"], function(dojo, dijit) {


      new Date("X"); // workaround for #11279, new Date("") == NaN




      dojo.declare(
       "dijit.form._DateTimeTextBox.__Constraints",
       [dijit.form.RangeBoundTextBox.__Constraints, dojo.date.locale.__FormatOptions], {
       // summary:
       //  Specifies both the rules on valid/invalid values (first/last date/time allowed),
       //  and also formatting options for how the date/time is displayed.
       // example:
       //  To restrict to dates within 2004, displayed in a long format like "December 25, 2005":
       // |  {min:'2004-01-01',max:'2004-12-31', formatLength:'long'}
      });




      dojo.declare(
       "dijit.form._DateTimeTextBox",
       [ dijit.form.RangeBoundTextBox, dijit._HasDropDown ],
       {
        // summary:
        //  Base class for validating, serializable, range-bound date or time text box.


        templateString: dojo.cache("dijit.form", "templates/DropDownBox.html"),


        // hasDownArrow: [const] Boolean
        //  Set this textbox to display a down arrow button, to open the drop down list.
        hasDownArrow: true,


        // openOnClick: [const] Boolean
        //  Set to true to open drop down upon clicking anywhere on the textbox.
        openOnClick: true,



        
        // constraints: dijit.form._DateTimeTextBox.__Constraints
        //  Despite the name, this parameter specifies both constraints on the input
        //  (including starting/ending dates/times allowed) as well as
        //  formatting options like whether the date is displayed in long (ex: December 25, 2005)
        //  or short (ex: 12/25/2005) format. See `dijit.form._DateTimeTextBox.__Constraints` for details.
        constraints: {},

        


        // Override ValidationTextBox.regExpGen().... we use a reg-ex generating function rather
        // than a straight regexp to deal with locale (plus formatting options too?)
        regExpGen: dojo.date.locale.regexp,


        // datePackage: String
        //  JavaScript namespace to find calendar routines.  Uses Gregorian calendar routines
        //  at dojo.date, by default.
        datePackage: "dojo.date",


        // Override _FormWidget.compare() to work for dates/times
        compare: function(/*Date*/ val1, /*Date*/ val2){
         var isInvalid1 = this._isInvalidDate(val1);
         var isInvalid2 = this._isInvalidDate(val2);
         return isInvalid1 ? (isInvalid2 ? 0 : -1) : (isInvalid2 ? 1 : dojo.date.compare(val1, val2, this._selector));
        },


        // flag to _HasDropDown to make drop down Calendar width == width
        forceWidth: true,


        format: function(/*Date*/ value, /*dojo.date.locale.__FormatOptions*/ constraints){
         // summary:
         //  Formats the value as a Date, according to specified locale (second argument)
         // tags:
         //  protected
         if(!value){ return ''; }
         return this.dateLocaleModule.format(value, constraints);
        },


        "parse": function(/*String*/ value, /*dojo.date.locale.__FormatOptions*/ constraints){
         // summary:
         //  Parses as string as a Date, according to constraints
         // tags:
         //  protected


         return this.dateLocaleModule.parse(value, constraints) || (this._isEmpty(value) ? null : undefined);  // Date
        },


        // Overrides ValidationTextBox.serialize() to serialize a date in canonical ISO format.
        serialize: function(/*anything*/ val, /*Object?*/ options){
         if(val.toGregorian){
          val = val.toGregorian();
         }
         return dojo.date.stamp.toISOString(val, options);
        },


        // dropDownDefaultValue: Date
        //  The default value to focus in the popupClass widget when the textbox value is empty.
        dropDownDefaultValue : new Date(),


        // value: Date
        //  The value of this widget as a JavaScript Date object. Use get("value") / set("value", val) to manipulate.
        //  When passed to the parser in markup, must be specified according to `dojo.date.stamp.fromISOString`
        value: new Date(""), // value.toString()="NaN"


        _blankValue: null, // used by filter() when the textbox is blank


        // popupClass: [protected extension] String
        //  Name of the popup widget class used to select a date/time.
        //  Subclasses should specify this.
        popupClass: "", // default is no popup = text only




        // _selector: [protected extension] String
        //  Specifies constraints.selector passed to dojo.date functions, should be either
        //  "date" or "time".
        //  Subclass must specify this.
        _selector: "",


        constructor: function(/*Object*/ args){
         var dateClass = args.datePackage ? args.datePackage + ".Date" : "Date";
         this.dateClassObj = dojo.getObject(dateClass, false);
         this.value = new this.dateClassObj("");


         this.datePackage = args.datePackage || this.datePackage;
         this.dateLocaleModule = dojo.getObject(this.datePackage + ".locale", false);
         this.regExpGen = this.dateLocaleModule.regexp;
         this._invalidDate = dijit.form._DateTimeTextBox.prototype.value.toString();
        },


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


         if(!this.hasDownArrow){
          this._buttonNode.style.display = "none";
         }


         // If openOnClick is true, we basically just want to treat the whole widget as the
         // button. We need to do that also if the actual drop down button will be hidden,
         // so that there's a mouse method for opening the drop down.
         if(this.openOnClick || !this.hasDownArrow){
          this._buttonNode = this.domNode;
          this.baseClass += " dijitComboBoxOpenOnClick";
         }
        },


        _setConstraintsAttr: function(/*Object*/ constraints){
         constraints.selector = this._selector;
         constraints.fullYear = true; // see #5465 - always format with 4-digit years
         var fromISO = dojo.date.stamp.fromISOString;
         if(typeof constraints.min == "string"){ constraints.min = fromISO(constraints.min); }
         if(typeof constraints.max == "string"){ constraints.max = fromISO(constraints.max); }
         this.inherited(arguments);
        },


        _isInvalidDate: function(/*Date*/ value){
         // summary:
         //  Runs various tests on the value, checking for invalid conditions
         // tags:
         //  private
         return !value || isNaN(value) || typeof value != "object" || value.toString() == this._invalidDate;
        },


        _setValueAttr: function(/*Date|String*/ value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
         // summary:
         //  Sets the date on this textbox. Note: value can be a JavaScript Date literal or a string to be parsed.
         if(value !== undefined){
          if(typeof value == "string"){
           value = dojo.date.stamp.fromISOString(value);
          }
          if(this._isInvalidDate(value)){
           value = null;
          }
          if(value instanceof Date && !(this.dateClassObj instanceof Date)){
           value = new this.dateClassObj(value);
          }
         }
         this.inherited(arguments);
         if(this.dropDown){
          this.dropDown.set('value', value, false);
         }
        },


        _set: function(attr, value){
         // Avoid spurious watch() notifications when value is changed to new Date object w/the same value
         if(attr == "value" && this.value instanceof Date && this.compare(value, this.value) == 0){
          return;
         }
         this.inherited(arguments);
        },


        _setDropDownDefaultValueAttr: function(/*Date*/ val){
         if(this._isInvalidDate(val)){
          // convert null setting into today's date, since there needs to be *some* default at all times.
           val = new this.dateClassObj()
            }
         this.dropDownDefaultValue = val;
        },


        openDropDown: function(/*Function*/ callback){
         // rebuild drop down every time, so that constraints get copied (#6002)
         if(this.dropDown){
          this.dropDown.destroy();
         }
         var PopupProto = dojo.getObject(this.popupClass, false),
          textBox = this,
          value = this.get("value");
         this.dropDown = new PopupProto({
          onChange: function(value){
            // this will cause InlineEditBox and other handlers to do stuff so make sure it's last
            dijit.form._DateTimeTextBox.superclass._setValueAttr.call(textBox, value, true);
           },
           id: this.id + "_popup",
           dir: textBox.dir,
           lang: textBox.lang,
          value: value,
          currentFocus: !this._isInvalidDate(value) ? value : this.dropDownDefaultValue,
           constraints: textBox.constraints,
          filterString: textBox.filterString, // for TimeTextBox, to filter times shown


           datePackage: textBox.datePackage,


           isDisabledDate: function(/*Date*/ date){
            // summary:
            //  disables dates outside of the min/max of the _DateTimeTextBox
            return !textBox.rangeCheck(date, textBox.constraints);
           }
          });


         this.inherited(arguments);
    • returns
      Date
    • chains:
      • dijit.form._DateTimeTextBox.superclass._setValueAttr: (call)
    • summary
  • dijit.form._DateTimeTextBox._getDisplayedValueAttr

    • type
      Function
    • source: [view]
         return this.textbox.value;
    • summary
  • dijit.form._DateTimeTextBox._setDisplayedValueAttr

    • type
      Function
    • parameters:
      • value: (typeof String)
      • priorityChange: (typeof Boolean)
    • source: [view]
         this._setValueAttr(this.parse(value, this.constraints), priorityChange, value);
    • summary
  • dijit.form._DateTimeTextBox._buttonNode.style.display

    • summary
  • dijit.form._DateTimeTextBox._buttonNode

    • summary
  • dijit.form._DateTimeTextBox.dropDown

    • summary
  • dijit.form._DateTimeTextBox.dateClassObj

    • summary
  • dijit.form._DateTimeTextBox.dateLocaleModule

    • summary
  • dijit.form._DateTimeTextBox._invalidDate

    • summary
  • dijit.form

    • type
      Object
    • summary
  • dijit

    • type
      Object
    • summary