How to set the default value of datafield - EXTJS 4

user1972227 picture user1972227 · Feb 19, 2013 · Viewed 19.3k times · Source
var startdt = Ext.create('Ext.form.DateField',{
    fieldLabel: 'Start Date',
    name: 'startdt',
    id: 'startdt',
    vtype: 'daterange',
    format: 'd/m/Y',
    endDateField: 'enddt', // id of the end date field
    value = new date()
    })

var enddt = Ext.create('Ext.form.DateField',{
    fieldLabel: 'End Date',
    name: 'enddt',
    id: 'enddt',
    format: 'd/m/Y',
    vtype: 'daterange',
    startDateField: 'startdt', // id of the start date field
    value = new date()
    })

this kind of method will let the window unable to show in center correctly. any idea to let the datefield set the default value with out using this method?

Answer

John Walker picture John Walker · Feb 19, 2013

this is an bug from extjs 4,u can try this following code

var startdt = Ext.create('Ext.form.DateField',{
    fieldLabel: 'Start Date',
    name: 'startdt',
    id: 'startdt',
    vtype: 'daterange',
    format: 'd/m/Y',
    endDateField: 'enddt', // id of the end date field
    listeners : {
    render : function(datefield) {
        /// code to convert GMT String to date object
        datefield.setValue(new Date());
                }
        }
    })

    var enddt = Ext.create('Ext.form.DateField',{
    fieldLabel: 'End Date',
    name: 'enddt',
    id: 'enddt',
    format: 'd/m/Y',
    vtype: 'daterange',
    startDateField: 'startdt', // id of the start date field
    listeners : {
    render : function(datefield) {
        /// code to convert GMT String to date object
        datefield.setValue(new Date());
                }
        }
    })