TimeTextBox.js 2.9 KB

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