PDA

View Full Version : 4.1.0 Datefields in form and loading unixtime values yields a blank box



stimpy
27 Apr 2012, 11:39 AM
I have a datefield in a form defined as follows


xtype:'datefield',
name:'myDate',
width:280,
fieldLabel:'my date label'

This renders a nice box with the attached date widget.

When iI call form load, I pass in a object which contains a date formatted as unixtime like this

"myDate":1329714000000

which I expect to parsed to some variant of

Mon Feb 20 2012 00:00:00 GMT-0500

however I consistently get a blank box which tells me that the parse has failed.

I tried using both dateFormat and dateRender


xtype:'datefield',
name:'myDate',
width:280,
dateFormat:'timestamp' // also tried 'time' and 'u'
fieldLabel:'my date label'

or

xtype:'datefield',
name:'myDate',
width:280,
renderer:Ext.util.Format.dateRenderer('u'),
fieldLabel:'my date label'


Can anyone tell me where I am going wrong ? ....

stimpy
27 Apr 2012, 12:13 PM
Ok using the code below in the success method of load() correctly sets the value but it seems this should be the function of the the formatters...


Ext.getCmp('myDate').setValue(new Date(action.result.data.myDate));

this still feels very wrong

slemmon
27 Apr 2012, 2:06 PM
Check out the altFormats config:
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.Date-cfg-altFormats



var dateVal = 1329714000000;


var dateField = Ext.widget('datefield', {
name:'myDate'
, width:280
, fieldLabel:'my date label'
, renderTo: Ext.getBody()
, altFormats: 'u'
, listeners: {
afterrender: function () {
this.setValue(dateVal);
}
}
});

stimpy
28 Apr 2012, 3:45 PM
@slemmon

thanks I will give that a try . However shouldn't the 'u' formatter work in dateFormat ?

Is this a bug or is it working as intended ?

slemmon
28 Apr 2012, 6:08 PM
Dunno. I'm actually not seeing dataFormat as a config option for the datefield class in 4.1.

stimpy
29 Apr 2012, 1:14 PM
Good catch

Its 'format' and 'altFormat'. I will give it a try .

dateFormat appears to exclusive to Ext.data.format.

Thanks

stimpy
30 Apr 2012, 3:17 AM
still not working. and I don't think your example should be either

'u' is decimal fraction of a second according to the docs

http://www.sencha.com/forum/newreply.php?p=791419&noquote=1

using format and
u returns 132
U returns 1329714000000

using alt format
u returns today's date in the format month/day/year ( 04/30/2012)
U returns 12/17/44106 which would be correct for seconds not miliseconds

strangely the docs do not appear to show there is an option to handle Epoch time as miliseconds

so what this means ( to me ) is that format has a bug and alt format is correct when using U .

Additionally I suggest that something like Ums be added for Epoch time as ms.

filipemartins
4 Oct 2012, 4:59 AM
Try add in your dateField altFormats 'Uuuu'. This worked for me.