Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / docs / source / TimeField.html
1 <html>\r
2 <head>\r
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    \r
4   <title>The source code</title>\r
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
7 </head>\r
8 <body  onload="prettyPrint();">\r
9     <pre class="prettyprint lang-js"><div id="cls-Ext.form.TimeField"></div>/**\r
10  * @class Ext.form.TimeField\r
11  * @extends Ext.form.ComboBox\r
12  * Provides a time input field with a time dropdown and automatic time validation.  Example usage:\r
13  * <pre><code>\r
14 new Ext.form.TimeField({\r
15     minValue: '9:00 AM',\r
16     maxValue: '6:00 PM',\r
17     increment: 30\r
18 });\r
19 </code></pre>\r
20  * @constructor\r
21  * Create a new TimeField\r
22  * @param {Object} config\r
23  * @xtype timefield\r
24  */\r
25 Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, {\r
26     <div id="cfg-Ext.form.TimeField-minValue"></div>/**\r
27      * @cfg {Date/String} minValue\r
28      * The minimum allowed time. Can be either a Javascript date object with a valid time value or a string \r
29      * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).\r
30      */\r
31     minValue : undefined,\r
32     <div id="cfg-Ext.form.TimeField-maxValue"></div>/**\r
33      * @cfg {Date/String} maxValue\r
34      * The maximum allowed time. Can be either a Javascript date object with a valid time value or a string \r
35      * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).\r
36      */\r
37     maxValue : undefined,\r
38     <div id="cfg-Ext.form.TimeField-minText"></div>/**\r
39      * @cfg {String} minText\r
40      * The error text to display when the date in the cell is before minValue (defaults to\r
41      * 'The time in this field must be equal to or after {0}').\r
42      */\r
43     minText : "The time in this field must be equal to or after {0}",\r
44     <div id="cfg-Ext.form.TimeField-maxText"></div>/**\r
45      * @cfg {String} maxText\r
46      * The error text to display when the time is after maxValue (defaults to\r
47      * 'The time in this field must be equal to or before {0}').\r
48      */\r
49     maxText : "The time in this field must be equal to or before {0}",\r
50     <div id="cfg-Ext.form.TimeField-invalidText"></div>/**\r
51      * @cfg {String} invalidText\r
52      * The error text to display when the time in the field is invalid (defaults to\r
53      * '{value} is not a valid time').\r
54      */\r
55     invalidText : "{0} is not a valid time",\r
56     <div id="cfg-Ext.form.TimeField-format"></div>/**\r
57      * @cfg {String} format\r
58      * The default time format string which can be overriden for localization support.  The format must be\r
59      * valid according to {@link Date#parseDate} (defaults to 'g:i A', e.g., '3:15 PM').  For 24-hour time\r
60      * format try 'H:i' instead.\r
61      */\r
62     format : "g:i A",\r
63     <div id="cfg-Ext.form.TimeField-altFormats"></div>/**\r
64      * @cfg {String} altFormats\r
65      * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined\r
66      * 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
67      */\r
68     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
69     <div id="cfg-Ext.form.TimeField-increment"></div>/**\r
70      * @cfg {Number} increment\r
71      * The number of minutes between each time value in the list (defaults to 15).\r
72      */\r
73     increment: 15,\r
74 \r
75     // private override\r
76     mode: 'local',\r
77     // private override\r
78     triggerAction: 'all',\r
79     // private override\r
80     typeAhead: false,\r
81     \r
82     // private - This is the date to use when generating time values in the absence of either minValue\r
83     // or maxValue.  Using the current date causes DST issues on DST boundary dates, so this is an \r
84     // arbitrary "safe" date that can be any date aside from DST boundary dates.\r
85     initDate: '1/1/2008',\r
86 \r
87     // private\r
88     initComponent : function(){\r
89         if(Ext.isDefined(this.minValue)){\r
90             this.setMinValue(this.minValue, true);\r
91         }\r
92         if(Ext.isDefined(this.maxValue)){\r
93             this.setMaxValue(this.maxValue, true);\r
94         }\r
95         if(!this.store){\r
96             this.generateStore(true);\r
97         }\r
98         Ext.form.TimeField.superclass.initComponent.call(this);\r
99     },\r
100     \r
101     <div id="method-Ext.form.TimeField-setMinValue"></div>/**\r
102      * Replaces any existing {@link #minValue} with the new time and refreshes the store.\r
103      * @param {Date/String} value The minimum time that can be selected\r
104      */\r
105     setMinValue: function(value, /* private */ initial){\r
106         this.setLimit(value, true, initial);\r
107         return this;\r
108     },\r
109 \r
110     <div id="method-Ext.form.TimeField-setMaxValue"></div>/**\r
111      * Replaces any existing {@link #maxValue} with the new time and refreshes the store.\r
112      * @param {Date/String} value The maximum time that can be selected\r
113      */\r
114     setMaxValue: function(value, /* private */ initial){\r
115         this.setLimit(value, false, initial);\r
116         return this;\r
117     },\r
118     \r
119     // private\r
120     generateStore: function(initial){\r
121         var min = this.minValue || new Date(this.initDate).clearTime(),\r
122             max = this.maxValue || new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1),\r
123             times = [];\r
124             \r
125         while(min <= max){\r
126             times.push(min.dateFormat(this.format));\r
127             min = min.add('mi', this.increment);\r
128         }\r
129         this.bindStore(times, initial);\r
130     },\r
131 \r
132     // private\r
133     setLimit: function(value, isMin, initial){\r
134         var d;\r
135         if(Ext.isString(value)){\r
136             d = this.parseDate(value);\r
137         }else if(Ext.isDate(value)){\r
138             d = value;\r
139         }\r
140         if(d){\r
141             var val = new Date(this.initDate).clearTime();\r
142             val.setHours(d.getHours(), d.getMinutes(), isMin ? 0 : 59, 0);\r
143             this[isMin ? 'minValue' : 'maxValue'] = val;\r
144             if(!initial){\r
145                 this.generateStore();\r
146             }\r
147         }\r
148     },\r
149     \r
150     // inherited docs\r
151     getValue : function(){\r
152         var v = Ext.form.TimeField.superclass.getValue.call(this);\r
153         return this.formatDate(this.parseDate(v)) || '';\r
154     },\r
155 \r
156     // inherited docs\r
157     setValue : function(value){\r
158         return Ext.form.TimeField.superclass.setValue.call(this, this.formatDate(this.parseDate(value)));\r
159     },\r
160 \r
161     // private overrides\r
162     validateValue : Ext.form.DateField.prototype.validateValue,\r
163     parseDate : Ext.form.DateField.prototype.parseDate,\r
164     formatDate : Ext.form.DateField.prototype.formatDate,\r
165 \r
166     // private\r
167     beforeBlur : function(){\r
168         var v = this.parseDate(this.getRawValue());\r
169         if(v){\r
170             this.setValue(v.dateFormat(this.format));\r
171         }\r
172         Ext.form.TimeField.superclass.beforeBlur.call(this);\r
173     }\r
174 \r
175     <div id="cfg-Ext.form.TimeField-grow"></div>/**\r
176      * @cfg {Boolean} grow @hide\r
177      */\r
178     <div id="cfg-Ext.form.TimeField-growMin"></div>/**\r
179      * @cfg {Number} growMin @hide\r
180      */\r
181     <div id="cfg-Ext.form.TimeField-growMax"></div>/**\r
182      * @cfg {Number} growMax @hide\r
183      */\r
184     <div id="method-Ext.form.TimeField-autoSize"></div>/**\r
185      * @hide\r
186      * @method autoSize\r
187      */\r
188 });\r
189 Ext.reg('timefield', Ext.form.TimeField);</pre>    \r
190 </body>\r
191 </html>