Dates are notoriously difficult to work with, especially when dealing with multiple and non-standard formats. This recipe will explore how to set the value of a date picker and how to use it in combination with different date formats.
We start by creating a simple Date Picker:
var dateField = Ext.create('Ext.form.field.Date', { fieldLabel: 'Pick a Date', renderTo: Ext.getBody() });
Now we can use the Date Picker's
setValue
method to give it a value. We will use British date formatting in this example with our date formatted as dd/mm/yyyy.dateField.setValue('31/01/2011');
After running this code we see that the field doesn't understand the format and so does not display or select a value.
To solve this problem we can specify the format that the date picker expects the values being passed to the
setValue
method are in. We do this by using theformat
configuration option.var dateField = Ext.create('Ext.form.field.Date', { fieldLabel...