1 | /*! |
---|
2 | * Ext JS Library 3.0.0 |
---|
3 | * Copyright(c) 2006-2009 Ext JS, LLC |
---|
4 | * licensing@extjs.com |
---|
5 | * http://www.extjs.com/license |
---|
6 | */ |
---|
7 | /** |
---|
8 | * @class Ext.form.TimeField |
---|
9 | * @extends Ext.form.ComboBox |
---|
10 | * Provides a time input field with a time dropdown and automatic time validation. Example usage: |
---|
11 | * <pre><code> |
---|
12 | new Ext.form.TimeField({ |
---|
13 | minValue: '9:00 AM', |
---|
14 | maxValue: '6:00 PM', |
---|
15 | increment: 30 |
---|
16 | }); |
---|
17 | </code></pre> |
---|
18 | * @constructor |
---|
19 | * Create a new TimeField |
---|
20 | * @param {Object} config |
---|
21 | * @xtype timefield |
---|
22 | */ |
---|
23 | Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, { |
---|
24 | /** |
---|
25 | * @cfg {Date/String} minValue |
---|
26 | * The minimum allowed time. Can be either a Javascript date object with a valid time value or a string |
---|
27 | * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to null). |
---|
28 | */ |
---|
29 | minValue : null, |
---|
30 | /** |
---|
31 | * @cfg {Date/String} maxValue |
---|
32 | * The maximum allowed time. Can be either a Javascript date object with a valid time value or a string |
---|
33 | * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to null). |
---|
34 | */ |
---|
35 | maxValue : null, |
---|
36 | /** |
---|
37 | * @cfg {String} minText |
---|
38 | * The error text to display when the date in the cell is before minValue (defaults to |
---|
39 | * 'The time in this field must be equal to or after {0}'). |
---|
40 | */ |
---|
41 | minText : "The time in this field must be equal to or after {0}", |
---|
42 | /** |
---|
43 | * @cfg {String} maxText |
---|
44 | * The error text to display when the time is after maxValue (defaults to |
---|
45 | * 'The time in this field must be equal to or before {0}'). |
---|
46 | */ |
---|
47 | maxText : "The time in this field must be equal to or before {0}", |
---|
48 | /** |
---|
49 | * @cfg {String} invalidText |
---|
50 | * The error text to display when the time in the field is invalid (defaults to |
---|
51 | * '{value} is not a valid time'). |
---|
52 | */ |
---|
53 | invalidText : "{0} is not a valid time", |
---|
54 | /** |
---|
55 | * @cfg {String} format |
---|
56 | * The default time format string which can be overriden for localization support. The format must be |
---|
57 | * valid according to {@link Date#parseDate} (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time |
---|
58 | * format try 'H:i' instead. |
---|
59 | */ |
---|
60 | format : "g:i A", |
---|
61 | /** |
---|
62 | * @cfg {String} altFormats |
---|
63 | * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined |
---|
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'). |
---|
65 | */ |
---|
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", |
---|
67 | /** |
---|
68 | * @cfg {Number} increment |
---|
69 | * The number of minutes between each time value in the list (defaults to 15). |
---|
70 | */ |
---|
71 | increment: 15, |
---|
72 | |
---|
73 | // private override |
---|
74 | mode: 'local', |
---|
75 | // private override |
---|
76 | triggerAction: 'all', |
---|
77 | // private override |
---|
78 | typeAhead: false, |
---|
79 | |
---|
80 | // private - This is the date to use when generating time values in the absence of either minValue |
---|
81 | // or maxValue. Using the current date causes DST issues on DST boundary dates, so this is an |
---|
82 | // arbitrary "safe" date that can be any date aside from DST boundary dates. |
---|
83 | initDate: '1/1/2008', |
---|
84 | |
---|
85 | // private |
---|
86 | initComponent : function(){ |
---|
87 | if(typeof this.minValue == "string"){ |
---|
88 | this.minValue = this.parseDate(this.minValue); |
---|
89 | } |
---|
90 | if(typeof this.maxValue == "string"){ |
---|
91 | this.maxValue = this.parseDate(this.maxValue); |
---|
92 | } |
---|
93 | |
---|
94 | if(!this.store){ |
---|
95 | var min = this.parseDate(this.minValue) || new Date(this.initDate).clearTime(); |
---|
96 | var max = this.parseDate(this.maxValue) || new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1); |
---|
97 | var times = []; |
---|
98 | while(min <= max){ |
---|
99 | times.push(min.dateFormat(this.format)); |
---|
100 | min = min.add('mi', this.increment); |
---|
101 | } |
---|
102 | this.store = times; |
---|
103 | } |
---|
104 | Ext.form.TimeField.superclass.initComponent.call(this); |
---|
105 | }, |
---|
106 | |
---|
107 | // inherited docs |
---|
108 | getValue : function(){ |
---|
109 | var v = Ext.form.TimeField.superclass.getValue.call(this); |
---|
110 | return this.formatDate(this.parseDate(v)) || ''; |
---|
111 | }, |
---|
112 | |
---|
113 | // inherited docs |
---|
114 | setValue : function(value){ |
---|
115 | return Ext.form.TimeField.superclass.setValue.call(this, this.formatDate(this.parseDate(value))); |
---|
116 | }, |
---|
117 | |
---|
118 | // private overrides |
---|
119 | validateValue : Ext.form.DateField.prototype.validateValue, |
---|
120 | parseDate : Ext.form.DateField.prototype.parseDate, |
---|
121 | formatDate : Ext.form.DateField.prototype.formatDate, |
---|
122 | |
---|
123 | // private |
---|
124 | beforeBlur : function(){ |
---|
125 | var v = this.parseDate(this.getRawValue()); |
---|
126 | if(v){ |
---|
127 | this.setValue(v.dateFormat(this.format)); |
---|
128 | } |
---|
129 | Ext.form.TimeField.superclass.beforeBlur.call(this); |
---|
130 | } |
---|
131 | |
---|
132 | /** |
---|
133 | * @cfg {Boolean} grow @hide |
---|
134 | */ |
---|
135 | /** |
---|
136 | * @cfg {Number} growMin @hide |
---|
137 | */ |
---|
138 | /** |
---|
139 | * @cfg {Number} growMax @hide |
---|
140 | */ |
---|
141 | /** |
---|
142 | * @hide |
---|
143 | * @method autoSize |
---|
144 | */ |
---|
145 | }); |
---|
146 | Ext.reg('timefield', Ext.form.TimeField); |
---|