]>
Commit | Line | Data |
---|---|---|
1354d172 AD |
1 | define("dijit/form/TimeTextBox", [ |
2 | "dojo/_base/declare", // declare | |
3 | "dojo/keys", // keys.DOWN_ARROW keys.ENTER keys.ESCAPE keys.TAB keys.UP_ARROW | |
4 | "dojo/_base/lang", // lang.hitch | |
5 | "../_TimePicker", | |
6 | "./_DateTimeTextBox" | |
7 | ], function(declare, keys, lang, _TimePicker, _DateTimeTextBox){ | |
8 | ||
9 | /*===== | |
10 | var _TimePicker = dijit._TimePicker; | |
11 | var _DateTimeTextBox = dijit.form._DateTimeTextBox; | |
12 | =====*/ | |
13 | ||
14 | // module: | |
15 | // dijit/form/TimeTextBox | |
16 | // summary: | |
17 | // A validating, serializable, range-bound time text box with a drop down time picker | |
18 | ||
19 | ||
20 | /*===== | |
21 | declare( | |
22 | "dijit.form.TimeTextBox.__Constraints", | |
23 | [dijit.form._DateTimeTextBox.__Constraints, dijit._TimePicker.__Constraints] | |
24 | ); | |
25 | =====*/ | |
26 | ||
27 | return declare("dijit.form.TimeTextBox", _DateTimeTextBox, { | |
28 | // summary: | |
29 | // A validating, serializable, range-bound time text box with a drop down time picker | |
30 | ||
31 | baseClass: "dijitTextBox dijitComboBox dijitTimeTextBox", | |
32 | popupClass: _TimePicker, | |
33 | _selector: "time", | |
34 | ||
35 | /*===== | |
36 | // constraints: dijit.form.TimeTextBox.__Constraints | |
37 | constraints:{}, | |
38 | =====*/ | |
39 | ||
40 | // value: Date | |
41 | // The value of this widget as a JavaScript Date object. Note that the date portion implies time zone and daylight savings rules. | |
42 | // | |
43 | // Example: | |
44 | // | new dijit.form.TimeTextBox({value: stamp.fromISOString("T12:59:59", new Date())}) | |
45 | // | |
46 | // When passed to the parser in markup, must be specified according to locale-independent | |
47 | // `stamp.fromISOString` format. | |
48 | // | |
49 | // Example: | |
50 | // | <input data-dojo-type='dijit.form.TimeTextBox' value='T12:34:00'> | |
51 | value: new Date(""), // value.toString()="NaN" | |
52 | //FIXME: in markup, you have no control over daylight savings | |
53 | ||
54 | _onKey: function(evt){ | |
55 | if(this.disabled || this.readOnly){ return; } | |
56 | this.inherited(arguments); | |
57 | ||
58 | // If the user has backspaced or typed some numbers, then filter the result list | |
59 | // by what they typed. Maybe there's a better way to detect this, like _handleOnChange()? | |
60 | switch(evt.keyCode){ | |
61 | case keys.ENTER: | |
62 | case keys.TAB: | |
63 | case keys.ESCAPE: | |
64 | case keys.DOWN_ARROW: | |
65 | case keys.UP_ARROW: | |
66 | // these keys have special meaning | |
67 | break; | |
68 | default: | |
69 | // setTimeout() because the keystroke hasn't yet appeared in the <input>, | |
70 | // so the get('displayedValue') call below won't give the result we want. | |
71 | setTimeout(lang.hitch(this, function(){ | |
72 | // set this.filterString to the filter to apply to the drop down list; | |
73 | // it will be used in openDropDown() | |
74 | var val = this.get('displayedValue'); | |
75 | this.filterString = (val && !this.parse(val, this.constraints)) ? val.toLowerCase() : ""; | |
76 | ||
77 | // close the drop down and reopen it, in order to filter the items shown in the list | |
78 | // and also since the drop down may need to be repositioned if the number of list items has changed | |
79 | // and it's being displayed above the <input> | |
80 | if(this._opened){ | |
81 | this.closeDropDown(); | |
82 | } | |
83 | this.openDropDown(); | |
84 | }), 0); | |
85 | } | |
86 | } | |
87 | }); | |
88 | }); |