[483] | 1 | define([ |
---|
| 2 | "dojo/_base/kernel", |
---|
| 3 | "dojo/_base/lang", |
---|
| 4 | "dojox/widget/DailyCalendar", |
---|
| 5 | "dijit/form/TextBox", |
---|
| 6 | "./DateTextBox", |
---|
| 7 | "dojo/_base/declare" |
---|
| 8 | ], function(kernel, lang, DailyCalendar, TextBox, DateTextBox, declare){ |
---|
| 9 | kernel.experimental("dojox/form/DayTextBox"); |
---|
| 10 | return declare("dojox.form.DayTextBox", DateTextBox, |
---|
| 11 | { |
---|
| 12 | // summary: |
---|
| 13 | // A validating, serializable, range-bound date text box with a popup calendar that contains just months. |
---|
| 14 | |
---|
| 15 | // popupClass: String |
---|
| 16 | // The popup widget to use. In this case, a calendar with just a Month view. |
---|
| 17 | popupClass: DailyCalendar, |
---|
| 18 | |
---|
| 19 | parse: function(displayVal){ |
---|
| 20 | return displayVal; |
---|
| 21 | }, |
---|
| 22 | |
---|
| 23 | format: function(value){ |
---|
| 24 | return value.getDate ? value.getDate() : value; |
---|
| 25 | }, |
---|
| 26 | validator: function(value){ |
---|
| 27 | var num = Number(value); |
---|
| 28 | var isInt = /(^-?\d\d*$)/.test(String(value)); |
---|
| 29 | return value == "" || value == null || (isInt && num >= 1 && num <= 31); |
---|
| 30 | }, |
---|
| 31 | |
---|
| 32 | _setValueAttr: function(value, priorityChange, formattedValue){ |
---|
| 33 | if(value){ |
---|
| 34 | if(value.getDate){ |
---|
| 35 | value = value.getDate(); |
---|
| 36 | } |
---|
| 37 | } |
---|
| 38 | TextBox.prototype._setValueAttr.call(this, value, priorityChange, formattedValue); |
---|
| 39 | }, |
---|
| 40 | |
---|
| 41 | openDropDown: function(){ |
---|
| 42 | this.inherited(arguments); |
---|
| 43 | |
---|
| 44 | this.dropDown.onValueSelected = lang.hitch(this, function(value){ |
---|
| 45 | this.focus(); // focus the textbox before the popup closes to avoid reopening the popup |
---|
| 46 | setTimeout(lang.hitch(this, "closeDropDown"), 1); // allow focus time to take |
---|
| 47 | |
---|
| 48 | TextBox.prototype._setValueAttr.call(this, String(value.getDate()), true, String(value.getDate())); |
---|
| 49 | }); |
---|
| 50 | } |
---|
| 51 | }); |
---|
| 52 | }); |
---|