PDA

View Full Version : How to get DateField in format 'd/m/Y'



Hatcha
28 Jan 2011, 1:16 AM
Hi, There

How to use DateField in format 'd/m/Y'?



var dateFieldStart = new Ext.form.DateField({
xtype: 'datefield',
allowBlank: false,
enableKeyEvents: true,
format:'d/m/Y',
width: 140,
listeners: {
'select' : {
fn: function(field, date) {
// ... do something useful here ...
onGoClick();
}
}
}
});


My problem about calendar 's Datefield on some client show in format 'm/d/Y'

eg: 01/02/2011 in my format ('d/m/Y')

but some client, DateField render calendar on Jan month When I choose 01/02/2011, It false rendered (:|



Thank for help,

hatcha:D

valititi
28 Jan 2011, 2:47 AM
first take care how you define it in your data store. There you can have something like :
{name: 'youFieldName', type: 'date', dateFormat: 'Y-m-d H:i:s'}

then in your form field :
{format:'d M Y',xtype:'datefield' . . . }

dduffy
28 Jan 2011, 2:51 AM
try
Ext.data.Field.prototype.dateFormat = 'd-m-Y H:i:s.u';

valititi
28 Jan 2011, 2:54 AM
hey ddufy !
he maybe not must use to redefine the global prototype, because in his application, maybe there are others dates, or times, that are not in this same format. So, for keeping "elastic" he must only format IN the current form, I think :-)

dduffy
28 Jan 2011, 6:30 AM
I would think you should have the same date format through out your application - otherwise you confuse te user.

valititi
28 Jan 2011, 6:34 AM
you right ddufy. I vote for this as you says, being consequent and not tire the users with different formats !! But, for example, on the app that i work now (and others before) THE CLIENT ORDER to have, a format on some date fields and OTHER :-( format in order dates fields