3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.form.TimeField"></div>/**
16 * @class Ext.form.TimeField
17 * @extends Ext.form.ComboBox
18 * Provides a time input field with a time dropdown and automatic time validation. Example usage:
20 new Ext.form.TimeField({
27 * Create a new TimeField
28 * @param {Object} config
31 Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, {
32 <div id="cfg-Ext.form.TimeField-minValue"></div>/**
33 * @cfg {Date/String} minValue
34 * The minimum allowed time. Can be either a Javascript date object with a valid time value or a string
35 * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).
38 <div id="cfg-Ext.form.TimeField-maxValue"></div>/**
39 * @cfg {Date/String} maxValue
40 * The maximum allowed time. Can be either a Javascript date object with a valid time value or a string
41 * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).
44 <div id="cfg-Ext.form.TimeField-minText"></div>/**
45 * @cfg {String} minText
46 * The error text to display when the date in the cell is before minValue (defaults to
47 * 'The time in this field must be equal to or after {0}').
49 minText : "The time in this field must be equal to or after {0}",
50 <div id="cfg-Ext.form.TimeField-maxText"></div>/**
51 * @cfg {String} maxText
52 * The error text to display when the time is after maxValue (defaults to
53 * 'The time in this field must be equal to or before {0}').
55 maxText : "The time in this field must be equal to or before {0}",
56 <div id="cfg-Ext.form.TimeField-invalidText"></div>/**
57 * @cfg {String} invalidText
58 * The error text to display when the time in the field is invalid (defaults to
59 * '{value} is not a valid time').
61 invalidText : "{0} is not a valid time",
62 <div id="cfg-Ext.form.TimeField-format"></div>/**
63 * @cfg {String} format
64 * The default time format string which can be overriden for localization support. The format must be
65 * valid according to {@link Date#parseDate} (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time
66 * format try 'H:i' instead.
69 <div id="cfg-Ext.form.TimeField-altFormats"></div>/**
70 * @cfg {String} altFormats
71 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
72 * 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').
74 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",
75 <div id="cfg-Ext.form.TimeField-increment"></div>/**
76 * @cfg {Number} increment
77 * The number of minutes between each time value in the list (defaults to 15).
88 // private - This is the date to use when generating time values in the absence of either minValue
89 // or maxValue. Using the current date causes DST issues on DST boundary dates, so this is an
90 // arbitrary "safe" date that can be any date aside from DST boundary dates.
93 initDateFormat: 'j/n/Y',
96 initComponent : function(){
97 if(Ext.isDefined(this.minValue)){
98 this.setMinValue(this.minValue, true);
100 if(Ext.isDefined(this.maxValue)){
101 this.setMaxValue(this.maxValue, true);
104 this.generateStore(true);
106 Ext.form.TimeField.superclass.initComponent.call(this);
109 <div id="method-Ext.form.TimeField-setMinValue"></div>/**
110 * Replaces any existing {@link #minValue} with the new time and refreshes the store.
111 * @param {Date/String} value The minimum time that can be selected
113 setMinValue: function(value, /* private */ initial){
114 this.setLimit(value, true, initial);
118 <div id="method-Ext.form.TimeField-setMaxValue"></div>/**
119 * Replaces any existing {@link #maxValue} with the new time and refreshes the store.
120 * @param {Date/String} value The maximum time that can be selected
122 setMaxValue: function(value, /* private */ initial){
123 this.setLimit(value, false, initial);
128 generateStore: function(initial){
129 var min = this.minValue || new Date(this.initDate).clearTime(),
130 max = this.maxValue || new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1),
134 times.push(min.dateFormat(this.format));
135 min = min.add('mi', this.increment);
137 this.bindStore(times, initial);
141 setLimit: function(value, isMin, initial){
143 if(Ext.isString(value)){
144 d = this.parseDate(value);
145 }else if(Ext.isDate(value)){
149 var val = new Date(this.initDate).clearTime();
150 val.setHours(d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
151 this[isMin ? 'minValue' : 'maxValue'] = val;
153 this.generateStore();
159 getValue : function(){
160 var v = Ext.form.TimeField.superclass.getValue.call(this);
161 return this.formatDate(this.parseDate(v)) || '';
165 setValue : function(value){
166 return Ext.form.TimeField.superclass.setValue.call(this, this.formatDate(this.parseDate(value)));
170 validateValue : Ext.form.DateField.prototype.validateValue,
172 formatDate : Ext.form.DateField.prototype.formatDate,
174 parseDate: function(value) {
175 if (!value || Ext.isDate(value)) {
179 var id = this.initDate + ' ',
180 idf = this.initDateFormat + ' ',
181 v = Date.parseDate(id + value, idf + this.format), // *** handle DST. note: this.format is a TIME-only format
182 af = this.altFormats;
185 if (!this.altFormatsArray) {
186 this.altFormatsArray = af.split("|");
188 for (var i = 0, afa = this.altFormatsArray, len = afa.length; i < len && !v; i++) {
189 v = Date.parseDate(id + value, idf + afa[i]);
196 Ext.reg('timefield', Ext.form.TimeField);</pre>