inputEx Documentation
Back to homepage
inputEx Documentation
> DateField.js
0.2.2
This is the source view for DateField.js
(function() { var inputEx = YAHOO.inputEx, lang = YAHOO.lang, Event = YAHOO.util.Event, Dom = YAHOO.util.Dom; /** * @class A Date Field. * @extends inputEx.StringField * @constructor * @param {Object} options Add the folowing options: *
*
dateFormat: default to 'm/d/Y'
*
*/ inputEx.DateField = function(options) { inputEx.DateField.superclass.constructor.call(this,options); }; lang.extend(inputEx.DateField, inputEx.StringField, /** * @scope inputEx.DateField.prototype */ { /** * Adds the 'inputEx-DateField' default className * @param {Object} options Options object (inputEx inputParams) as passed to the constructor */ setOptions: function(options) { inputEx.DateField.superclass.setOptions.call(this, options); // Overwrite options this.options.className = options.className ? options.className : 'inputEx-Field inputEx-DateField'; this.options.messages.invalid = inputEx.messages.invalidDate; // Added options this.options.dateFormat = options.dateFormat || inputEx.messages.defaultDateFormat; }, /** * Specific Date validation depending of the 'format' option */ validate: function() { var value = this.el.value; var ladate = value.split("/"); if( ladate.length != 3) { return false; } if ( isNaN(parseInt(ladate[0],10)) || isNaN(parseInt(ladate[1],10)) || isNaN(parseInt(ladate[2],10))) { return false; } var formatSplit = this.options.dateFormat.split("/"); var yearIndex = inputEx.indexOf('Y',formatSplit); if (ladate[yearIndex].length!=4) { return false; } // Avoid 3-digits years... var d = parseInt(ladate[ inputEx.indexOf('d',formatSplit) ],10); var Y = parseInt(ladate[yearIndex],10); var m = parseInt(ladate[ inputEx.indexOf('m',formatSplit) ],10)-1; var unedate = new Date(Y,m,d); var annee = unedate.getFullYear(); return ((unedate.getDate() == d) && (unedate.getMonth() == m) && (annee == Y)); }, /** * Format the date according to options.dateFormat * @param {Date} val Date to set * @param {boolean} [sendUpdatedEvt] (optional) Wether this setValue should fire the updatedEvt or not (default is true, pass false to NOT send the event) */ setValue: function(val, sendUpdatedEvt) { // Don't try to parse a date if there is no date if( val === '' ) { inputEx.DateField.superclass.setValue.call(this, '', sendUpdatedEvt); return; } var str = ""; // DATETIME if (val instanceof Date) { str = this.options.dateFormat.replace('Y',val.getFullYear()); var m = val.getMonth()+1; str = str.replace('m', ((m < 10)? '0':'')+m); var d = val.getDate(); str = str.replace('d', ((d < 10)? '0':'')+d); } // else date must match this.options.dateFormat else { str = val; } inputEx.DateField.superclass.setValue.call(this, str, sendUpdatedEvt); }, /** * Return value in DATETIME format (use getFormattedValue() to have 04/10/2002-like format) * @return {Date} The javascript Date object */ getValue: function() { // let parent class function check if typeInvite, etc... var value = inputEx.DateField.superclass.getValue.call(this); // Hack to validate if field not required and empty if (value === '') { return '';} //var ladate = this.el.value.split("/"); var ladate = value.split("/"); var formatSplit = this.options.dateFormat.split('/'); var d = parseInt(ladate[ inputEx.indexOf('d',formatSplit) ],10); var Y = parseInt(ladate[ inputEx.indexOf('Y',formatSplit) ],10); var m = parseInt(ladate[ inputEx.indexOf('m',formatSplit) ],10)-1; return (new Date(Y,m,d)); } }); // Specific message for the container inputEx.messages.invalidDate = "Invalid date, ex: 03/27/2008"; /** * Register this class as "date" type */ inputEx.registerType("date", inputEx.DateField); })();
Pages
Index
Getting Started
Overview
Markup structure
Migrate from 0.1.0
Field development
DOM functions
Internationalization
Visualization
Examples
Classes
(treeview)
inputEx
inputEx.AutoComplete
inputEx.BirthdateField
inputEx.CheckBox
inputEx.ColorField
inputEx.ColorField2
inputEx.CombineField
inputEx.DateField
inputEx.DatePickerField
inputEx.DateSplitField
inputEx.DateTimeField
inputEx.DSSelectField
inputEx.EmailField
inputEx.Field
inputEx.FileField
inputEx.Form
inputEx.formForMethod
inputEx.FrenchDate
inputEx.FrenchPhone
inputEx.generateServiceForm
inputEx.Group
inputEx.HiddenField
inputEx.ImagemapField
inputEx.InPlaceEdit
inputEx.IntegerField
inputEx.IPv4Field
inputEx.JsonSchema
inputEx.JsonSchema.Builder
inputEx.ListField
inputEx.MapField
inputEx.MenuField
inputEx.MultiAutoComplete
inputEx.MultiSelectField
inputEx.NumberField
inputEx.PairField
inputEx.PasswordField
inputEx.RadioButton
inputEx.RadioField
inputEx.RTEField
inputEx.SelectField
inputEx.SliderField
inputEx.StringField
inputEx.Textarea
inputEx.TimeField
inputEx.TreeField
inputEx.TypeField
inputEx.UneditableField
inputEx.UpperCaseField
inputEx.UrlField
inputEx.VectorField
inputEx.widget
inputEx.widget.DataTable
inputEx.widget.DDList
inputEx.widget.DDListItem
inputEx.widget.Dialog
inputEx.widget.InputExCellEditor
inputEx.widget.JsonTreeInspector
Files
AutoComplete.js
BirthdateField.js
CheckBox.js
ColorField.js
ColorField2.js
CombineField.js
DataTable-beta.js
DateField.js
DatePickerField.js
DateSplitField.js
DateTimeField.js
ddlist.js
Dialog-beta.js
DSSelectField.js
EmailField.js
Field.js
FileField-beta.js
Form.js
fr.js
FrenchDate.js
FrenchPhone.js
Group.js
HiddenField.js
ImagemapField.js
InPlaceEdit.js
inputex-loader.js
inputex-rpc.js
inputex.js
IntegerField.js
IPv4Field.js
it.js
json-schema.js
json-tree-inspector.js
ListField.js
MapField.js
MenuField.js
MultiAutoComplete.js
MultiSelectField.js
NumberField.js
PairField.js
PasswordField.js
RadioButton.js
RadioField.js
RTEField.js
SelectField.js
SliderField.js
StringField.js
Textarea.js
TimeField.js
TreeField.js
TypeField.js
UneditableField.js
UpperCaseField.js
UrlField.js
VectorField.js
Visus.js
Copyright (c) 2007-2009
Eric Abouaf
. All rights reserved.
Generated by
JsDoc Toolkit
2.0.0 on Wed, 04 Mar 2009 15:41:29 GMT using
neyricjslibs-template
.