+++ /dev/null
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
- * @class Ext.form.DateField\r
- * @extends Ext.form.TriggerField\r
- * Provides a date input field with a {@link Ext.DatePicker} dropdown and automatic date validation.\r
-* @constructor\r
-* Create a new DateField\r
-* @param {Object} config\r
- */\r
-Ext.form.DateField = Ext.extend(Ext.form.TriggerField, {\r
- /**\r
- * @cfg {String} format\r
- * The default date format string which can be overriden for localization support. The format must be\r
- * valid according to {@link Date#parseDate} (defaults to 'm/d/Y').\r
- */\r
- format : "m/d/Y",\r
- /**\r
- * @cfg {String} altFormats\r
- * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined\r
- * format (defaults to 'm/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d').\r
- */\r
- altFormats : "m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d",\r
- /**\r
- * @cfg {String} disabledDaysText\r
- * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')\r
- */\r
- disabledDaysText : "Disabled",\r
- /**\r
- * @cfg {String} disabledDatesText\r
- * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')\r
- */\r
- disabledDatesText : "Disabled",\r
- /**\r
- * @cfg {String} minText\r
- * The error text to display when the date in the cell is before minValue (defaults to\r
- * 'The date in this field must be after {minValue}').\r
- */\r
- minText : "The date in this field must be equal to or after {0}",\r
- /**\r
- * @cfg {String} maxText\r
- * The error text to display when the date in the cell is after maxValue (defaults to\r
- * 'The date in this field must be before {maxValue}').\r
- */\r
- maxText : "The date in this field must be equal to or before {0}",\r
- /**\r
- * @cfg {String} invalidText\r
- * The error text to display when the date in the field is invalid (defaults to\r
- * '{value} is not a valid date - it must be in the format {format}').\r
- */\r
- invalidText : "{0} is not a valid date - it must be in the format {1}",\r
- /**\r
- * @cfg {String} triggerClass\r
- * An additional CSS class used to style the trigger button. The trigger will always get the\r
- * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'\r
- * which displays a calendar icon).\r
- */\r
- triggerClass : 'x-form-date-trigger',\r
- /**\r
- * @cfg {Boolean} showToday\r
- * False to hide the footer area of the DatePicker containing the Today button and disable the keyboard\r
- * handler for spacebar that selects the current date (defaults to true).\r
- */\r
- showToday : true,\r
- /**\r
- * @cfg {Date/String} minValue\r
- * The minimum allowed date. Can be either a Javascript date object or a string date in a\r
- * valid format (defaults to null).\r
- */\r
- /**\r
- * @cfg {Date/String} maxValue\r
- * The maximum allowed date. Can be either a Javascript date object or a string date in a\r
- * valid format (defaults to null).\r
- */\r
- /**\r
- * @cfg {Array} disabledDays\r
- * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).\r
- */\r
- /**\r
- * @cfg {Array} disabledDates\r
- * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular\r
- * expression so they are very powerful. Some examples:\r
- * <ul>\r
- * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>\r
- * <li>["03/08", "09/16"] would disable those days for every year</li>\r
- * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>\r
- * <li>["03/../2006"] would disable every day in March 2006</li>\r
- * <li>["^03"] would disable every day in every March</li>\r
- * </ul>\r
- * Note that the format of the dates included in the array should exactly match the {@link #format} config.\r
- * In order to support regular expressions, if you are using a date format that has "." in it, you will have to\r
- * escape the dot when restricting dates. For example: ["03\\.08\\.03"].\r
- */\r
- /**\r
- * @cfg {String/Object} autoCreate\r
- * A DomHelper element spec, or true for a default element spec (defaults to\r
- * {tag: "input", type: "text", size: "10", autocomplete: "off"})\r
- */\r
-\r
- // private\r
- defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},\r
-\r
- initComponent : function(){\r
- Ext.form.DateField.superclass.initComponent.call(this);\r
- \r
- this.addEvents(\r
- /**\r
- * @event select\r
- * Fires when a date is selected via the date picker.\r
- * @param {Ext.form.DateField} this\r
- * @param {Date} date The date that was selected\r
- */\r
- 'select'\r
- );\r
- \r
- if(typeof this.minValue == "string"){\r
- this.minValue = this.parseDate(this.minValue);\r
- }\r
- if(typeof this.maxValue == "string"){\r
- this.maxValue = this.parseDate(this.maxValue);\r
- }\r
- this.disabledDatesRE = null;\r
- this.initDisabledDays();\r
- },\r
-\r
- // private\r
- initDisabledDays : function(){\r
- if(this.disabledDates){\r
- var dd = this.disabledDates;\r
- var re = "(?:";\r
- for(var i = 0; i < dd.length; i++){\r
- re += dd[i];\r
- if(i != dd.length-1) re += "|";\r
- }\r
- this.disabledDatesRE = new RegExp(re + ")");\r
- }\r
- },\r
-\r
- /**\r
- * Replaces any existing disabled dates with new values and refreshes the DatePicker.\r
- * @param {Array} disabledDates An array of date strings (see the {@link #disabledDates} config\r
- * for details on supported values) used to disable a pattern of dates.\r
- */\r
- setDisabledDates : function(dd){\r
- this.disabledDates = dd;\r
- this.initDisabledDays();\r
- if(this.menu){\r
- this.menu.picker.setDisabledDates(this.disabledDatesRE);\r
- }\r
- },\r
-\r
- /**\r
- * Replaces any existing disabled days (by index, 0-6) with new values and refreshes the DatePicker.\r
- * @param {Array} disabledDays An array of disabled day indexes. See the {@link #disabledDays} config\r
- * for details on supported values.\r
- */\r
- setDisabledDays : function(dd){\r
- this.disabledDays = dd;\r
- if(this.menu){\r
- this.menu.picker.setDisabledDays(dd);\r
- }\r
- },\r
-\r
- /**\r
- * Replaces any existing {@link #minValue} with the new value and refreshes the DatePicker.\r
- * @param {Date} value The minimum date that can be selected\r
- */\r
- setMinValue : function(dt){\r
- this.minValue = (typeof dt == "string" ? this.parseDate(dt) : dt);\r
- if(this.menu){\r
- this.menu.picker.setMinDate(this.minValue);\r
- }\r
- },\r
-\r
- /**\r
- * Replaces any existing {@link #maxValue} with the new value and refreshes the DatePicker.\r
- * @param {Date} value The maximum date that can be selected\r
- */\r
- setMaxValue : function(dt){\r
- this.maxValue = (typeof dt == "string" ? this.parseDate(dt) : dt);\r
- if(this.menu){\r
- this.menu.picker.setMaxDate(this.maxValue);\r
- }\r
- },\r
-\r
- // private\r
- validateValue : function(value){\r
- value = this.formatDate(value);\r
- if(!Ext.form.DateField.superclass.validateValue.call(this, value)){\r
- return false;\r
- }\r
- if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid\r
- return true;\r
- }\r
- var svalue = value;\r
- value = this.parseDate(value);\r
- if(!value){\r
- this.markInvalid(String.format(this.invalidText, svalue, this.format));\r
- return false;\r
- }\r
- var time = value.getTime();\r
- if(this.minValue && time < this.minValue.getTime()){\r
- this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));\r
- return false;\r
- }\r
- if(this.maxValue && time > this.maxValue.getTime()){\r
- this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));\r
- return false;\r
- }\r
- if(this.disabledDays){\r
- var day = value.getDay();\r
- for(var i = 0; i < this.disabledDays.length; i++) {\r
- if(day === this.disabledDays[i]){\r
- this.markInvalid(this.disabledDaysText);\r
- return false;\r
- }\r
- }\r
- }\r
- var fvalue = this.formatDate(value);\r
- if(this.disabledDatesRE && this.disabledDatesRE.test(fvalue)){\r
- this.markInvalid(String.format(this.disabledDatesText, fvalue));\r
- return false;\r
- }\r
- return true;\r
- },\r
-\r
- // private\r
- // Provides logic to override the default TriggerField.validateBlur which just returns true\r
- validateBlur : function(){\r
- return !this.menu || !this.menu.isVisible();\r
- },\r
-\r
- /**\r
- * Returns the current date value of the date field.\r
- * @return {Date} The date value\r
- */\r
- getValue : function(){\r
- return this.parseDate(Ext.form.DateField.superclass.getValue.call(this)) || "";\r
- },\r
-\r
- /**\r
- * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid\r
- * date, using DateField.format as the date format, according to the same rules as {@link Date#parseDate}\r
- * (the default format used is "m/d/Y").\r
- * <br />Usage:\r
- * <pre><code>\r
-//All of these calls set the same date value (May 4, 2006)\r
-\r
-//Pass a date object:\r
-var dt = new Date('5/4/2006');\r
-dateField.setValue(dt);\r
-\r
-//Pass a date string (default format):\r
-dateField.setValue('05/04/2006');\r
-\r
-//Pass a date string (custom format):\r
-dateField.format = 'Y-m-d';\r
-dateField.setValue('2006-05-04');\r
-</code></pre>\r
- * @param {String/Date} date The date or valid date string\r
- */\r
- setValue : function(date){\r
- Ext.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));\r
- },\r
-\r
- // private\r
- parseDate : function(value){\r
- if(!value || Ext.isDate(value)){\r
- return value;\r
- }\r
- var v = Date.parseDate(value, this.format);\r
- if(!v && this.altFormats){\r
- if(!this.altFormatsArray){\r
- this.altFormatsArray = this.altFormats.split("|");\r
- }\r
- for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){\r
- v = Date.parseDate(value, this.altFormatsArray[i]);\r
- }\r
- }\r
- return v;\r
- },\r
-\r
- // private\r
- onDestroy : function(){\r
- if(this.menu) {\r
- this.menu.destroy();\r
- }\r
- if(this.wrap){\r
- this.wrap.remove();\r
- }\r
- Ext.form.DateField.superclass.onDestroy.call(this);\r
- },\r
-\r
- // private\r
- formatDate : function(date){\r
- return Ext.isDate(date) ? date.dateFormat(this.format) : date;\r
- },\r
-\r
- // private\r
- menuListeners : {\r
- select: function(m, d){\r
- this.setValue(d);\r
- this.fireEvent('select', this, d);\r
- },\r
- show : function(){ // retain focus styling\r
- this.onFocus();\r
- },\r
- hide : function(){\r
- this.focus.defer(10, this);\r
- var ml = this.menuListeners;\r
- this.menu.un("select", ml.select, this);\r
- this.menu.un("show", ml.show, this);\r
- this.menu.un("hide", ml.hide, this);\r
- }\r
- },\r
-\r
- /**\r
- * @method onTriggerClick\r
- * @hide\r
- */\r
- // private\r
- // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker\r
- onTriggerClick : function(){\r
- if(this.disabled){\r
- return;\r
- }\r
- if(this.menu == null){\r
- this.menu = new Ext.menu.DateMenu();\r
- }\r
- Ext.apply(this.menu.picker, {\r
- minDate : this.minValue,\r
- maxDate : this.maxValue,\r
- disabledDatesRE : this.disabledDatesRE,\r
- disabledDatesText : this.disabledDatesText,\r
- disabledDays : this.disabledDays,\r
- disabledDaysText : this.disabledDaysText,\r
- format : this.format,\r
- showToday : this.showToday,\r
- minText : String.format(this.minText, this.formatDate(this.minValue)),\r
- maxText : String.format(this.maxText, this.formatDate(this.maxValue))\r
- });\r
- this.menu.on(Ext.apply({}, this.menuListeners, {\r
- scope:this\r
- }));\r
- this.menu.picker.setValue(this.getValue() || new Date());\r
- this.menu.show(this.el, "tl-bl?");\r
- },\r
-\r
- // private\r
- beforeBlur : function(){\r
- var v = this.parseDate(this.getRawValue());\r
- if(v){\r
- this.setValue(v);\r
- }\r
- }\r
-\r
- /**\r
- * @cfg {Boolean} grow @hide\r
- */\r
- /**\r
- * @cfg {Number} growMin @hide\r
- */\r
- /**\r
- * @cfg {Number} growMax @hide\r
- */\r
- /**\r
- * @hide\r
- * @method autoSize\r
- */\r
-});\r
-Ext.reg('datefield', Ext.form.DateField);
\ No newline at end of file