Use the following code to create a basic inputEx DateField.
1 | new inputEx.DateField({parentEl: 'container1', value: new Date(), showMsg: true}); |
view plain | print | ? |
Set the formatDate to your localized date format ! Here is the french format :
1 | new inputEx.DateField({dateFormat: 'd/m/Y', value: '27/03/2008', parentEl: 'container2', showMsg: true}); |
view plain | print | ? |
The DateField returns a javascript Date object instance :
1 | var exampleDiv = YAHOO.util.Dom.get('container3'); |
2 | var dateField = new inputEx.DateField({value: new Date(), parentEl: exampleDiv, showMsg: true, required:true, typeInvite:'m/d/Y'}); |
3 | dateField.updatedEvt.subscribe(function() { |
4 | exampleDiv.appendChild( inputEx.cn('div', null, null, dateField.getValue()) ); |
5 | }); |
6 | |
7 | var button1 = inputEx.cn('button', null, null, 'setValue()'); |
8 | exampleDiv.appendChild(button1); |
9 | YAHOO.util.Event.addListener(button1, 'click', function() { dateField.setValue("11/26/1980"); }); |
10 | |
11 | var button2 = inputEx.cn('button', null, null, 'getValue()'); |
12 | exampleDiv.appendChild(button2); |
13 | YAHOO.util.Event.addListener(button2, 'click', function() { alert(dateField.getValue()); }); |
view plain | print | ? |
The setValue/getValue methods will parse/format the dates to the valueFormat option.
1 | // Instantiate the date field |
2 | var stringdateField = new inputEx.DateField({value: new Date(), parentEl: 'container4', showMsg: true, required:true, typeInvite:'m/d/Y', valueFormat: 'Y-m-d'}); |
3 | |
4 | // Logger |
5 | var exampleDiv = YAHOO.util.Dom.get('container4'); |
6 | stringdateField.updatedEvt.subscribe(function() { |
7 | exampleDiv.appendChild( inputEx.cn('div', null, null, stringdateField.getValue()) ); |
8 | }); |
9 | |
10 | // Set the value according to the valueFormat |
11 | var button1 = inputEx.cn('button', null, null, 'setValue()'); |
12 | exampleDiv.appendChild(button1); |
13 | YAHOO.util.Event.addListener(button1, 'click', function() { stringdateField.setValue("1980-11-16"); }); |
14 | |
15 | // The returned value will use the valueFormat too |
16 | var button2 = inputEx.cn('button', null, null, 'getValue()'); |
17 | exampleDiv.appendChild(button2); |
18 | YAHOO.util.Event.addListener(button2, 'click', function() { alert(stringdateField.getValue()); }); |
view plain | print | ? |