PDA

View Full Version : Datefield in form not populating



rnxfod
18 Jul 2013, 2:22 AM
I'm trying to load json data into a form, all other components are being set with their values except the datefield.
Some one help me figure out what I'm not doing right.

Model

Ext.define('App.model.entities.Phone', {
extend: 'Ext.data.Model',
idProperty: 'phone',
fields: [
'phone',
'name',
...
'email',
{ name: 'dateofbirth', type: 'date', dateFormat: 'Y-m-d H:i:s' },
...
]
});


Form

Ext.define('App.view.forms.customercare.RegisterSubscriberForm', {
extend: 'Ext.form.Panel',
alias: 'widget.registersubscriber.form',


id: 'registersubscriber_form',
...
items: [
...
{ xtype: 'datefield',
id: 'registersubscriber_date_of_birth',
name: 'dateofbirth',
fieldLabel: 'Date Of Birth',
maxValue: new Date(),
format: 'Y-m-d H:i:s',
//altFormats: 'Y-m-d H:i:s|d/m/Y,H:i|d/m/Y',
submitFormat: 'Y-m-d H:i:s'
},
...



JSON data


{"itemlist":[{"phone":"085545798","name":"SMITH JOHN","sex":"M" ... "dateofbirth":"1987-04-07 00:00:00.0", ... }]}

slemmon
23 Jul 2013, 1:48 PM
Try using the following date parse format for that date: dateFormat: 'Y-m-d H:i:s.u'




Ext.define('App.model.entities.Phone', {
extend: 'Ext.data.Model',
idProperty: 'phone',
fields: [
'phone',
'name',
'email',
{ name: 'dateofbirth', type: 'date', dateFormat: 'Y-m-d H:i:s.u' }
]
});


var rec = Ext.create('App.model.entities.Phone', {
"phone": "085545798",
"name": "SMITH JOHN",
"sex": "M",
"dateofbirth": "1987-04-07 00:00:00.0"
});


Ext.define('App.view.forms.customercare.RegisterSubscriberForm', {
extend: 'Ext.form.Panel',
alias: 'widget.registersubscriber',


items: [{
xtype: 'datefield',
id: 'registersubscriber_date_of_birth',
name: 'dateofbirth',
fieldLabel: 'Date Of Birth',
maxValue: new Date(),
format: 'Y-m-d H:i:s',
submitFormat: 'Y-m-d H:i:s'
}]
});


Ext.widget('registersubscriber', {
renderTo: document.body,
width: 300,
height: 300,
listeners: {
boxready: function () {
this.loadRecord(rec);
console.log(this.getRecord());
}
}
});

rnxfod
24 Jul 2013, 10:30 AM
Thanks very much. would never have guessed it.