1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-form.field.Time-method-constructor'><span id='Ext-form.field.Time'>/**
2 </span></span> * @class Ext.form.field.Time
3 * @extends Ext.form.field.Picker
4 * <p>Provides a time input field with a time dropdown and automatic time validation.</p>
5 * <p>This field recognizes and uses JavaScript Date objects as its main {@link #value} type (only the time
6 * portion of the date is used; the month/day/year are ignored). In addition, it recognizes string values which
7 * are parsed according to the {@link #format} and/or {@link #altFormats} configs. These may be reconfigured
8 * to use time formats appropriate for the user's locale.</p>
9 * <p>The field may be limited to a certain range of times by using the {@link #minValue} and {@link #maxValue}
10 * configs, and the interval between time options in the dropdown can be changed with the {@link #increment} config.</p>
11 * {@img Ext.form.Time/Ext.form.Time.png Ext.form.Time component}
12 * <p>Example usage:</p>
13 * <pre><code>
14 Ext.create('Ext.form.Panel', {
18 renderTo: Ext.getBody(),
22 fieldLabel: 'Time In',
30 fieldLabel: 'Time Out',
37 </code></pre>
39 * Create a new Time field
40 * @param {Object} config
43 Ext.define('Ext.form.field.Time', {
44 extend:'Ext.form.field.Picker',
45 alias: 'widget.timefield',
46 requires: ['Ext.form.field.Date', 'Ext.picker.Time', 'Ext.view.BoundListKeyNav', 'Ext.Date'],
47 alternateClassName: ['Ext.form.TimeField', 'Ext.form.Time'],
49 <span id='Ext-form.field.Time-cfg-triggerCls'> /**
50 </span> * @cfg {String} triggerCls
51 * An additional CSS class used to style the trigger button. The trigger will always get the
52 * {@link #triggerBaseCls} by default and <tt>triggerCls</tt> will be <b>appended</b> if specified.
53 * Defaults to <tt>'x-form-time-trigger'</tt> for the Time field trigger.
55 triggerCls: Ext.baseCSSPrefix + 'form-time-trigger',
57 <span id='Ext-form.field.Time-cfg-minValue'> /**
58 </span> * @cfg {Date/String} minValue
59 * The minimum allowed time. Can be either a Javascript date object with a valid time value or a string
60 * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).
63 <span id='Ext-form.field.Time-cfg-maxValue'> /**
64 </span> * @cfg {Date/String} maxValue
65 * The maximum allowed time. Can be either a Javascript date object with a valid time value or a string
66 * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).
69 <span id='Ext-form.field.Time-cfg-minText'> /**
70 </span> * @cfg {String} minText
71 * The error text to display when the entered time is before {@link #minValue} (defaults to
72 * 'The time in this field must be equal to or after {0}').
74 minText : "The time in this field must be equal to or after {0}",
76 <span id='Ext-form.field.Time-cfg-maxText'> /**
77 </span> * @cfg {String} maxText
78 * The error text to display when the entered time is after {@link #maxValue} (defaults to
79 * 'The time in this field must be equal to or before {0}').
81 maxText : "The time in this field must be equal to or before {0}",
83 <span id='Ext-form.field.Time-cfg-invalidText'> /**
84 </span> * @cfg {String} invalidText
85 * The error text to display when the time in the field is invalid (defaults to
86 * '{value} is not a valid time').
88 invalidText : "{0} is not a valid time",
90 <span id='Ext-form.field.Time-cfg-format'> /**
91 </span> * @cfg {String} format
92 * The default time format string which can be overriden for localization support. The format must be
93 * valid according to {@link Ext.Date#parse} (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time
94 * format try 'H:i' instead.
96 format : "g:i A",
98 <span id='Ext-form.field.Time-cfg-submitFormat'> /**
99 </span> * @cfg {String} submitFormat The date format string which will be submitted to the server.
100 * The format must be valid according to {@link Ext.Date#parse} (defaults to <tt>{@link #format}</tt>).
103 <span id='Ext-form.field.Time-cfg-altFormats'> /**
104 </span> * @cfg {String} altFormats
105 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
106 * 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|gi a|hi a|giA|hiA|gi A|hi A').
108 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|gi a|hi a|giA|hiA|gi A|hi A",
110 <span id='Ext-form.field.Time-cfg-increment'> /**
111 </span> * @cfg {Number} increment
112 * The number of minutes between each time value in the list (defaults to 15).
116 <span id='Ext-form.field.Time-cfg-pickerMaxHeight'> /**
117 </span> * @cfg {Number} pickerMaxHeight
118 * The maximum height of the {@link Ext.picker.Time} dropdown. Defaults to 300.
120 pickerMaxHeight: 300,
122 <span id='Ext-form.field.Time-cfg-selectOnTab'> /**
123 </span> * @cfg {Boolean} selectOnTab
124 * Whether the Tab key should select the currently highlighted item. Defaults to <tt>true</tt>.
128 <span id='Ext-form.field.Time-property-initDate'> /**
130 * This is the date to use when generating time values in the absence of either minValue
131 * or maxValue. Using the current date causes DST issues on DST boundary dates, so this is an
132 * arbitrary "safe" date that can be any date aside from DST boundary dates.
134 initDate: '1/1/2008',
135 initDateFormat: 'j/n/Y',
138 initComponent: function() {
151 initValue: function() {
155 // If a String value was supplied, try to convert it to a proper Date object
156 if (Ext.isString(value)) {
157 me.value = me.rawToValue(value);
163 <span id='Ext-form.field.Time-method-setMinValue'> /**
164 </span> * Replaces any existing {@link #minValue} with the new time and refreshes the picker's range.
165 * @param {Date/String} value The minimum time that can be selected
167 setMinValue: function(value) {
170 me.setLimit(value, true);
172 picker.setMinValue(me.minValue);
176 <span id='Ext-form.field.Time-method-setMaxValue'> /**
177 </span> * Replaces any existing {@link #maxValue} with the new time and refreshes the picker's range.
178 * @param {Date/String} value The maximum time that can be selected
180 setMaxValue: function(value) {
183 me.setLimit(value, false);
185 picker.setMaxValue(me.maxValue);
189 <span id='Ext-form.field.Time-method-setLimit'> /**
191 * Updates either the min or max value. Converts the user's value into a Date object whose
192 * year/month/day is set to the {@link #initDate} so that only the time fields are significant.
194 setLimit: function(value, isMin) {
197 if (Ext.isString(value)) {
198 d = me.parseDate(value);
200 else if (Ext.isDate(value)) {
204 val = Ext.Date.clearTime(new Date(me.initDate));
205 val.setHours(d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
206 me[isMin ? 'minValue' : 'maxValue'] = val;
210 rawToValue: function(rawValue) {
211 return this.parseDate(rawValue) || rawValue || null;
214 valueToRaw: function(value) {
215 return this.formatDate(this.parseDate(value));
218 <span id='Ext-form.field.Time-method-getErrors'> /**
219 </span> * Runs all of Time's validations and returns an array of any errors. Note that this first
220 * runs Text's validations, so the returned array is an amalgamation of all field errors.
221 * The additional validation checks are testing that the time format is valid, that the chosen
222 * time is within the {@link #minValue} and {@link #maxValue} constraints set.
223 * @param {Mixed} value The value to get errors for (defaults to the current field value)
224 * @return {Array} All validation errors for this field
226 getErrors: function(value) {
228 format = Ext.String.format,
229 errors = me.callParent(arguments),
230 minValue = me.minValue,
231 maxValue = me.maxValue,
234 value = me.formatDate(value || me.processRawValue(me.getRawValue()));
236 if (value === null || value.length < 1) { // if it's blank and textfield didn't flag it then it's valid
240 date = me.parseDate(value);
242 errors.push(format(me.invalidText, value, me.format));
246 if (minValue && date < minValue) {
247 errors.push(format(me.minText, me.formatDate(minValue)));
250 if (maxValue && date > maxValue) {
251 errors.push(format(me.maxText, me.formatDate(maxValue)));
257 formatDate: function() {
258 return Ext.form.field.Date.prototype.formatDate.apply(this, arguments);
261 <span id='Ext-form.field.Time-method-parseDate'> /**
263 * Parses an input value into a valid Date object.
264 * @param {String/Date} value
266 parseDate: function(value) {
267 if (!value || Ext.isDate(value)) {
272 val = me.safeParse(value, me.format),
273 altFormats = me.altFormats,
274 altFormatsArray = me.altFormatsArray,
278 if (!val && altFormats) {
279 altFormatsArray = altFormatsArray || altFormats.split('|');
280 len = altFormatsArray.length;
281 for (; i < len && !val; ++i) {
282 val = me.safeParse(value, altFormatsArray[i]);
288 safeParse: function(value, format){
294 if (utilDate.formatContainsDateInfo(format)) {
295 // assume we've been given a full date
296 result = utilDate.parse(value, format);
298 // Use our initial safe date
299 parsedDate = utilDate.parse(me.initDate + ' ' + value, me.initDateFormat + ' ' + format);
308 getSubmitValue: function() {
310 format = me.submitFormat || me.format,
311 value = me.getValue();
313 return value ? Ext.Date.format(value, format) : null;
316 <span id='Ext-form.field.Time-method-createPicker'> /**
318 * Creates the {@link Ext.picker.Time}
320 createPicker: function() {
322 picker = Ext.create('Ext.picker.Time', {
328 minValue: me.minValue,
329 maxValue: me.maxValue,
330 increment: me.increment,
332 ownerCt: this.ownerCt,
333 renderTo: document.body,
334 maxHeight: me.pickerMaxHeight,
335 focusOnToFront: false
338 me.mon(picker.getSelectionModel(), {
339 selectionchange: me.onListSelect,
346 <span id='Ext-form.field.Time-method-onExpand'> /**
348 * Enables the key nav for the Time picker when it is expanded.
349 * TODO this is largely the same logic as ComboBox, should factor out.
351 onExpand: function() {
353 keyNav = me.pickerKeyNav,
354 selectOnTab = me.selectOnTab,
355 picker = me.getPicker(),
356 lastSelected = picker.getSelectionModel().lastSelected,
360 keyNav = me.pickerKeyNav = Ext.create('Ext.view.BoundListKeyNav', this.inputEl, {
365 this.selectHighlighted(e);
368 // Tab key event is allowed to propagate to field
372 // stop tab monitoring from Ext.form.field.Trigger so it doesn't short-circuit selectOnTab
374 me.ignoreMonitorTab = true;
377 Ext.defer(keyNav.enable, 1, keyNav); //wait a bit so it doesn't react to the down arrow opening the picker
379 // Highlight the last selected item and scroll it into view
381 itemNode = picker.getNode(lastSelected);
383 picker.highlightItem(itemNode);
384 picker.el.scrollChildIntoView(itemNode, false);
389 <span id='Ext-form.field.Time-method-onCollapse'> /**
391 * Disables the key nav for the Time picker when it is collapsed.
393 onCollapse: function() {
395 keyNav = me.pickerKeyNav;
398 me.ignoreMonitorTab = false;
402 <span id='Ext-form.field.Time-method-onListSelect'> /**
404 * Handles a time being selected from the Time picker.
406 onListSelect: function(list, recordArray) {
408 record = recordArray[0],
409 val = record ? record.get('date') : null;
411 me.fireEvent('select', me, val);
412 me.picker.clearHighlight();
418 </pre></pre></body></html>