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