TimeTextBox.js 2.9 KB

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