O'Reilly logo

Ext JS 4 Web Application Development Cookbook by Stuart Ashworth, Andrew Duncan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading and parsing Dates into a Date field

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.

How to do it...

  1. We start by creating a simple Date Picker:
    var dateField = Ext.create('Ext.form.field.Date', {
        fieldLabel: 'Pick a Date',
        renderTo: Ext.getBody()
    });
  2. 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');
  3. After running this code we see that the field doesn't understand the format and so does not display or select a value.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required