dojo.declare("net.yutuo.dojo.DateTextBox", [dijit.form.DateTextBox], {
validator: function(value, constraints) {
value = this.myParse(value, constraints);
return (new RegExp("^(?:" + this.regExpGen(constraints) + ")"+(this.required?"":"?")+"$")).test(value)
&& (!this.required || !this._isEmpty(value))
&& (this._isEmpty(value) || this.parse(value, constraints) !== undefined);
},
parse: function(value, constraints){
value = this.myParse(value, constraints);
return this.dateLocaleModule.parse(value, constraints)
|| (this._isEmpty(value) ? null : undefined);
},
myParse: function (value, constraints) {
var dateStr = null;
if (value.match(/^d{6}$/)) {
dateStr = value.substring(0, 2) + '-' + value.substring(2, 4) + '-' + value.substring(4, 6);
} else if (value.match(/^d{8}$/)) {
dateStr = value.substring(0, 4) + '-' + value.substring(4, 6) + '-' + value.substring(6, 8);
} else if (value.match(/^d{4}$/)) {
dateStr = new Date().getFullYear() + '-' + value.substring(0, 2) + '-' + value.substring(2, 4);
}
if (dateStr) {
var date = this.dateLocaleModule.parse(dateStr, {selector: 'date', datePattern: 'yy-M-d'});
if (date) {
return this.dateLocaleModule.format(date, constraints);
}
}
return value;
}
});
|