1 if(!dojo._hasResource["dijit.form._DateTimeTextBox"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit.form._DateTimeTextBox"] = true;
3 dojo.provide("dijit.form._DateTimeTextBox");
5 dojo.require("dojo.date");
6 dojo.require("dojo.date.locale");
7 dojo.require("dojo.date.stamp");
8 dojo.require("dijit.form.ValidationTextBox");
12 "dijit.form._DateTimeTextBox.__Constraints",
13 [dijit.form.RangeBoundTextBox.__Constraints, dojo.date.locale.__FormatOptions]
18 "dijit.form._DateTimeTextBox",
19 dijit.form.RangeBoundTextBox,
22 // A validating, serializable, range-bound date or time text box.
24 // constraints: dijit.form._DateTimeTextBox.__Constraints
29 regExpGen: dojo.date.locale.regexp,
30 compare: dojo.date.compare,
31 format: function(/*Date*/ value, /*dojo.date.locale.__FormatOptions*/ constraints){
32 // summary: formats the value as a Date, according to constraints
33 if(!value){ return ''; }
34 return dojo.date.locale.format(value, constraints);
36 parse: function(/*String*/ value, /*dojo.date.locale.__FormatOptions*/ constraints){
37 // summary: parses the value as a Date, according to constraints
38 return dojo.date.locale.parse(value, constraints) || undefined; /* can't return null to getValue since that's special */
41 serialize: dojo.date.stamp.toISOString,
44 // The value of this widget as a JavaScript Date object. Use `getValue`/`setValue` to manipulate.
45 // When passed to the parser in markup, must be specified according to `dojo.date.stamp.fromISOString`
46 value: new Date(""), // value.toString()="NaN"
49 // Name of the popup widget class used to select a date/time
50 popupClass: "", // default is no popup = text only
53 postMixInProperties: function(){
54 //dijit.form.RangeBoundTextBox.prototype.postMixInProperties.apply(this, arguments);
55 this.inherited(arguments);
56 if(!this.value || this.value.toString() == dijit.form._DateTimeTextBox.prototype.value.toString()){
57 this.value = undefined;
59 var constraints = this.constraints;
60 constraints.selector = this._selector;
61 constraints.fullYear = true; // see #5465 - always format with 4-digit years
62 var fromISO = dojo.date.stamp.fromISOString;
63 if(typeof constraints.min == "string"){ constraints.min = fromISO(constraints.min); }
64 if(typeof constraints.max == "string"){ constraints.max = fromISO(constraints.max); }
67 _onFocus: function(/*Event*/ evt){
68 // summary: open the TimePicker popup
72 setValue: function(/*Date*/ value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
74 // Sets the date on this textbox. Note that `value` must be a Javascript Date object.
75 this.inherited(arguments);
77 // #3948: fix blank date on popup only
78 if(!value){value=new Date();}
79 this._picker.setValue(value);
85 // opens the TimePicker, and sets the onValueSelected value
87 if(this.disabled || this.readOnly || !this.popupClass){return;}
92 var PopupProto=dojo.getObject(this.popupClass, false);
93 this._picker = new PopupProto({
94 onValueSelected: function(value){
96 textBox.focus(); // focus the textbox before the popup closes to avoid reopening the popup
97 setTimeout(dojo.hitch(textBox, "_close"), 1); // allow focus time to take
99 // this will cause InlineEditBox and other handlers to do stuff so make sure it's last
100 dijit.form._DateTimeTextBox.superclass.setValue.call(textBox, value, true);
103 constraints: textBox.constraints,
104 isDisabledDate: function(/*Date*/ date){
106 // disables dates outside of the min/max of the _DateTimeTextBox
107 var compare = dojo.date.compare;
108 var constraints = textBox.constraints;
109 return constraints && (constraints.min && (compare(constraints.min, date, "date") > 0) ||
110 (constraints.max && compare(constraints.max, date, "date") < 0));
113 this._picker.setValue(this.getValue() || new Date());
119 around: this.domNode,
120 onCancel: dojo.hitch(this, this._close),
121 onClose: function(){ textBox._opened=false; }
126 dojo.marginBox(this._picker.domNode,{ w:this.domNode.offsetWidth });
131 dijit.popup.close(this._picker);
137 // summary: called magically when focus has shifted away from this widget and it's dropdown
140 // teardown so that constraints will be rebuilt next time (redundant reference: #6002)
141 this._picker.destroy();
144 this.inherited(arguments);
145 // don't focus on <input>. the user has explicitly focused on something else.
148 getDisplayedValue:function(){
149 return this.textbox.value;
152 setDisplayedValue:function(/*String*/ value, /*Boolean?*/ priorityChange){
153 this.setValue(this.parse(value, this.constraints), priorityChange, value);
158 this._picker.destroy();
161 this.inherited(arguments);
164 _onKeyPress: function(/*Event*/e){
165 if(dijit.form._DateTimeTextBox.superclass._onKeyPress.apply(this, arguments)){
166 if(this._opened && e.keyCode == dojo.keys.ESCAPE && !e.shiftKey && !e.ctrlKey && !e.altKey){