| 1 |
define([ |
| 2 |
"dojo/_base/kernel", |
| 3 |
"dojo/_base/lang", |
| 4 |
"dojox/widget/YearlyCalendar", |
| 5 |
"dijit/form/TextBox", |
| 6 |
"./DateTextBox", |
| 7 |
"dojo/_base/declare" |
| 8 |
], function(kernel, lang, YearlyCalendar, TextBox, DateTextBox, declare){ |
| 9 |
kernel.experimental("dojox/form/DateTextBox"); |
| 10 |
return declare("dojox.form.YearTextBox", DateTextBox, |
| 11 |
{ |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
popupClass: YearlyCalendar, |
| 16 |
|
| 17 |
format: function(value){ |
| 18 |
|
| 19 |
if(typeof value == "string"){ |
| 20 |
return value; |
| 21 |
} |
| 22 |
else if(value.getFullYear){ |
| 23 |
return value.getFullYear(); |
| 24 |
} |
| 25 |
return value; |
| 26 |
}, |
| 27 |
|
| 28 |
validator: function(value){ |
| 29 |
return value == "" || value == null || /(^-?\d\d*$)/.test(String(value)); |
| 30 |
}, |
| 31 |
|
| 32 |
_setValueAttr: function(value, priorityChange, formattedValue){ |
| 33 |
if(value){ |
| 34 |
if(value.getFullYear){ |
| 35 |
value = value.getFullYear(); |
| 36 |
} |
| 37 |
} |
| 38 |
TextBox.prototype._setValueAttr.call(this, value, priorityChange, formattedValue); |
| 39 |
}, |
| 40 |
|
| 41 |
openDropDown: function(){ |
| 42 |
this.inherited(arguments); |
| 43 |
|
| 44 |
|
| 45 |
this.dropDown.onValueSelected = lang.hitch(this, function(value){ |
| 46 |
this.focus(); |
| 47 |
setTimeout(lang.hitch(this, "closeDropDown"), 1); |
| 48 |
TextBox.prototype._setValueAttr.call(this,value, true, value); |
| 49 |
}); |
| 50 |
}, |
| 51 |
|
| 52 |
parse: function( value, constraints){ |
| 53 |
return value || (this._isEmpty(value) ? null : undefined); |
| 54 |
}, |
| 55 |
|
| 56 |
filter: function(val){ |
| 57 |
if(val && val.getFullYear){ |
| 58 |
return val.getFullYear().toString(); |
| 59 |
} |
| 60 |
return this.inherited(arguments); |
| 61 |
} |
| 62 |
}); |
| 63 |
}); |