3 * Copyright(c) 2006-2010 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.form.TimeField
\r
9 * @extends Ext.form.ComboBox
\r
10 * Provides a time input field with a time dropdown and automatic time validation. Example usage:
\r
12 new Ext.form.TimeField({
\r
13 minValue: '9:00 AM',
\r
14 maxValue: '6:00 PM',
\r
19 * Create a new TimeField
\r
20 * @param {Object} config
\r
23 Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, {
\r
25 * @cfg {Date/String} minValue
\r
26 * The minimum allowed time. Can be either a Javascript date object with a valid time value or a string
\r
27 * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).
\r
29 minValue : undefined,
\r
31 * @cfg {Date/String} maxValue
\r
32 * The maximum allowed time. Can be either a Javascript date object with a valid time value or a string
\r
33 * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).
\r
35 maxValue : undefined,
\r
37 * @cfg {String} minText
\r
38 * The error text to display when the date in the cell is before minValue (defaults to
\r
39 * 'The time in this field must be equal to or after {0}').
\r
41 minText : "The time in this field must be equal to or after {0}",
\r
43 * @cfg {String} maxText
\r
44 * The error text to display when the time is after maxValue (defaults to
\r
45 * 'The time in this field must be equal to or before {0}').
\r
47 maxText : "The time in this field must be equal to or before {0}",
\r
49 * @cfg {String} invalidText
\r
50 * The error text to display when the time in the field is invalid (defaults to
\r
51 * '{value} is not a valid time').
\r
53 invalidText : "{0} is not a valid time",
\r
55 * @cfg {String} format
\r
56 * The default time format string which can be overriden for localization support. The format must be
\r
57 * valid according to {@link Date#parseDate} (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time
\r
58 * format try 'H:i' instead.
\r
62 * @cfg {String} altFormats
\r
63 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
\r
64 * format (defaults to 'g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H').
\r
66 altFormats : "g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H",
\r
68 * @cfg {Number} increment
\r
69 * The number of minutes between each time value in the list (defaults to 15).
\r
76 triggerAction: 'all',
\r
80 // private - This is the date to use when generating time values in the absence of either minValue
\r
81 // or maxValue. Using the current date causes DST issues on DST boundary dates, so this is an
\r
82 // arbitrary "safe" date that can be any date aside from DST boundary dates.
\r
83 initDate: '1/1/2008',
\r
86 initComponent : function(){
\r
87 if(Ext.isDefined(this.minValue)){
\r
88 this.setMinValue(this.minValue, true);
\r
90 if(Ext.isDefined(this.maxValue)){
\r
91 this.setMaxValue(this.maxValue, true);
\r
94 this.generateStore(true);
\r
96 Ext.form.TimeField.superclass.initComponent.call(this);
\r
100 * Replaces any existing {@link #minValue} with the new time and refreshes the store.
\r
101 * @param {Date/String} value The minimum time that can be selected
\r
103 setMinValue: function(value, /* private */ initial){
\r
104 this.setLimit(value, true, initial);
\r
109 * Replaces any existing {@link #maxValue} with the new time and refreshes the store.
\r
110 * @param {Date/String} value The maximum time that can be selected
\r
112 setMaxValue: function(value, /* private */ initial){
\r
113 this.setLimit(value, false, initial);
\r
118 generateStore: function(initial){
\r
119 var min = this.minValue || new Date(this.initDate).clearTime(),
\r
120 max = this.maxValue || new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1),
\r
124 times.push(min.dateFormat(this.format));
\r
125 min = min.add('mi', this.increment);
\r
127 this.bindStore(times, initial);
\r
131 setLimit: function(value, isMin, initial){
\r
133 if(Ext.isString(value)){
\r
134 d = this.parseDate(value);
\r
135 }else if(Ext.isDate(value)){
\r
139 var val = new Date(this.initDate).clearTime();
\r
140 val.setHours(d.getHours(), d.getMinutes(), isMin ? 0 : 59, 0);
\r
141 this[isMin ? 'minValue' : 'maxValue'] = val;
\r
143 this.generateStore();
\r
149 getValue : function(){
\r
150 var v = Ext.form.TimeField.superclass.getValue.call(this);
\r
151 return this.formatDate(this.parseDate(v)) || '';
\r
155 setValue : function(value){
\r
156 return Ext.form.TimeField.superclass.setValue.call(this, this.formatDate(this.parseDate(value)));
\r
159 // private overrides
\r
160 validateValue : Ext.form.DateField.prototype.validateValue,
\r
161 parseDate : Ext.form.DateField.prototype.parseDate,
\r
162 formatDate : Ext.form.DateField.prototype.formatDate,
\r
165 beforeBlur : function(){
\r
166 var v = this.parseDate(this.getRawValue());
\r
168 this.setValue(v.dateFormat(this.format));
\r
170 Ext.form.TimeField.superclass.beforeBlur.call(this);
\r
174 * @cfg {Boolean} grow @hide
\r
177 * @cfg {Number} growMin @hide
\r
180 * @cfg {Number} growMax @hide
\r
187 Ext.reg('timefield', Ext.form.TimeField);