inputEx - DateField Usage

Basic DateField creation

Use the following code to create a basic inputEx DateField.

1new inputEx.DateField({parentEl: 'container1', value: new Date(), showMsg: true}); 
view plain | print | ?

Change date format

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

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

Updated event and return value

The DateField returns a javascript Date object instance :

1var exampleDiv = YAHOO.util.Dom.get('container3'); 
2var dateField = new inputEx.DateField({value: new Date(),  parentEl: exampleDiv, showMsg: true, required:true, typeInvite:'m/d/Y'});  
3dateField.updatedEvt.subscribe(function() { 
4    exampleDiv.appendChild( inputEx.cn('div'nullnull, dateField.getValue()) );  
5}); 
6 
7var button1 = inputEx.cn('button'nullnull'setValue()'); 
8exampleDiv.appendChild(button1);  
9YAHOO.util.Event.addListener(button1, 'click'function() { dateField.setValue("11/26/1980"); }); 
10 
11var button2 = inputEx.cn('button'nullnull'getValue()'); 
12exampleDiv.appendChild(button2);  
13YAHOO.util.Event.addListener(button2, 'click'function() { alert(dateField.getValue()); }); 
view plain | print | ?

Use a string input/output formatting

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

1// Instantiate the date field 
2var stringdateField = new inputEx.DateField({value: new Date(),  parentEl: 'container4', showMsg: true, required:true, typeInvite:'m/d/Y', valueFormat: 'Y-m-d'});  
3 
4// Logger 
5var exampleDiv = YAHOO.util.Dom.get('container4'); 
6stringdateField.updatedEvt.subscribe(function() { 
7    exampleDiv.appendChild( inputEx.cn('div'nullnull, stringdateField.getValue()) );  
8}); 
9 
10// Set the value according to the valueFormat 
11var button1 = inputEx.cn('button'nullnull'setValue()'); 
12exampleDiv.appendChild(button1);  
13YAHOO.util.Event.addListener(button1, 'click'function() { stringdateField.setValue("1980-11-16"); }); 
14 
15// The returned value will use the valueFormat too 
16var button2 = inputEx.cn('button'nullnull'getValue()'); 
17exampleDiv.appendChild(button2);  
18YAHOO.util.Event.addListener(button2, 'click'function() { alert(stringdateField.getValue()); }); 
view plain | print | ?