/* * Ext JS Library 1.0.1 * Copyright(c) 2006-2007, Ext JS, LLC. * licensing@extjs.com * * http://www.extjs.com/license */ /** * @class Ext.form.DateField * @extends Ext.form.TriggerField * Provides a date input field with a {@link Ext.DatePicker} dropdown and automatic date validation. * @constructor * Create a new DateField * @param {Object} config */ Ext.form.DateField = function(config){ Ext.form.DateField.superclass.constructor.call(this, config); if(typeof this.minValue == "string") this.minValue = this.parseDate(this.minValue); if(typeof this.maxValue == "string") this.maxValue = this.parseDate(this.maxValue); this.ddMatch = null; if(this.disabledDates){ var dd = this.disabledDates; var re = "(?:"; for(var i = 0; i < dd.length; i++){ re += dd[i]; if(i != dd.length-1) re += "|"; } this.ddMatch = new RegExp(re + ")"); } }; Ext.extend(Ext.form.DateField, Ext.form.TriggerField, { /** * @cfg {String} format * The default date format string which can be overriden for localization support. The format must be * valid according to {@link Date#parseDate} (defaults to 'm/d/y'). */ format : "m/d/y", /** * @cfg {Array} disabledDays * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null). */ disabledDays : null, /** * @cfg {String} disabledDaysText * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled') */ disabledDaysText : "Disabled", /** * @cfg {Array} disabledDates * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular * expression so they are very powerful. Some examples: *
//All of these calls set the same date value (May 4, 2006)
//Pass a date object:
var dt = new Date('5/4/06');
dateField.setValue(dt);
//Pass a date string (default format):
dateField.setValue('5/4/06');
//Pass a date string (custom format):
dateField.format = 'Y-m-d';
dateField.setValue('2006-5-4');
* @param {String/Date} date The date or valid date string
*/
setValue : function(date){
Ext.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
},
// private
parseDate : function(value){
return (!value || value instanceof Date) ?
value : Date.parseDate(value, this.format);
},
// private
formatDate : function(date){
return (!date || !(date instanceof Date)) ?
date : date.dateFormat(this.format);
},
// private
menuListeners : {
select: function(m, d){
this.setValue(d);
},
show : function(){ // retain focus styling
this.onFocus();
},
hide : function(){
this.focus();
var ml = this.menuListeners;
this.menu.un("select", ml.select, this);
this.menu.un("show", ml.show, this);
this.menu.un("hide", ml.hide, this);
}
},
// private
// Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
onTriggerClick : function(){
if(this.disabled){
return;
}
if(this.menu == null){
this.menu = new Ext.menu.DateMenu();
}
Ext.apply(this.menu.picker, {
minDate : this.minValue,
maxDate : this.maxValue,
disabledDatesRE : this.ddMatch,
disabledDatesText : this.disabledDatesText,
disabledDays : this.disabledDays,
disabledDaysText : this.disabledDaysText,
format : this.format,
minText : String.format(this.minText, this.formatDate(this.minValue)),
maxText : String.format(this.maxText, this.formatDate(this.maxValue))
});
this.menu.on(Ext.apply({}, this.menuListeners, {
scope:this
}));
this.menu.picker.setValue(this.getValue() || new Date());
this.menu.show(this.el, "tl-bl?");
}
});