Thursday, 6 June 2013

How to set default date to Model Date Field in Sencha Touch 2

In Sencha Touch 2, Model class supports different field types ( auto, int, string, boolean, date etc).  Today we are going to see how we can set the current data and time as default Value to the Model date field. Following is the implementation
Ext.define('MyApp.model.FormModel', {
    extend: 'Ext.data.Model',
    alias: 'model.formmodel',

    config: {
        fields: [
            {
                dateFormat: 'Y-m-d H:i:s',
                defaultValue: new Date(),
                name: 'createdDate',
                type: 'date'
            }
        ]
    }
});

You can also set date while creating Model instance using Ext.create(). Here is the code

var formModel = Ext.create('MyApp.model.FormModel',{
    createdDate: new Date()
});

Hope, you enjoyed this Post.

No comments:

Post a Comment