# inputEx - DateField Usage

## Basic DateField creation

Use the following code to create a basic inputEx DateField.

new inputEx.DateField({parentEl: 'container1', value: new Date(), showMsg: true});

## Change date format

Set the formatDate to your localized date format ! Here is the french format :

new inputEx.DateField({dateFormat: 'd/m/Y', value: '27/03/2008', parentEl: 'container2', showMsg: true});

## Updated event and return value

The DateField returns a javascript Date object instance :

var exampleDiv = YAHOO.util.Dom.get('container3'); var dateField = new inputEx.DateField({value: new Date(), parentEl: exampleDiv, showMsg: true, required:true, typeInvite:'m/d/Y'}); dateField.updatedEvt.subscribe(function() { exampleDiv.appendChild( inputEx.cn('div', null, null, dateField.getValue()) ); }); var button1 = inputEx.cn('button', null, null, 'setValue()'); exampleDiv.appendChild(button1); YAHOO.util.Event.addListener(button1, 'click', function() { dateField.setValue("11/26/1980"); }); var button2 = inputEx.cn('button', null, null, 'getValue()'); exampleDiv.appendChild(button2); YAHOO.util.Event.addListener(button2, 'click', function() { alert(dateField.getValue()); });

## Use a string input/output formatting

The setValue/getValue methods will parse/format the dates to the valueFormat option.

// Instantiate the date field var stringdateField = new inputEx.DateField({value: new Date(), parentEl: 'container4', showMsg: true, required:true, typeInvite:'m/d/Y', valueFormat: 'Y-m-d'}); // Logger var exampleDiv = YAHOO.util.Dom.get('container4'); stringdateField.updatedEvt.subscribe(function() { exampleDiv.appendChild( inputEx.cn('div', null, null, stringdateField.getValue()) ); }); // Set the value according to the valueFormat var button1 = inputEx.cn('button', null, null, 'setValue()'); exampleDiv.appendChild(button1); YAHOO.util.Event.addListener(button1, 'click', function() { stringdateField.setValue("1980-11-16"); }); // The returned value will use the valueFormat too var button2 = inputEx.cn('button', null, null, 'getValue()'); exampleDiv.appendChild(button2); YAHOO.util.Event.addListener(button2, 'click', function() { alert(stringdateField.getValue()); });