View Full Version : different display and value formats for timefield

26 Oct 2010, 12:06 PM
Timefields are combo boxes.
Is it possible to have one time format for displayField and a different one for valueField??
I want to display time in 12 hr format('g A') and want to get it in 24 hr format('H') on form submit.

xtype: 'timefield',
id: 'time',
fieldLabel: 'Time',
format: 'g A', //12 hr format
increment: 60,
value: '12 AM',
width: 68,
allowBlank: false,
forceSelection: true

Please help.

27 Oct 2010, 3:16 AM
Please help with this.
I have a timefield in my form. It displays time in 12-hr format but I want the value to be in 24-hr format before submit.
I have this..

form.findField('time').setValue(convertTimeFormat(form.findField('time').getValue(), 12) + ':00:00');

but it clears the timefield.
The convertTimeFormat function is ok.

27 Oct 2010, 4:53 AM
Extend timeField for your utility

Ext.ux.TimeField = Ext.extend(Ext.form.TimeField, {
format: 'g:i a',
getValue : function(){
var v = Ext.form.TimeField.superclass.getValue.call(this);
return this.formatDateToSubmit(this.parseDate(v)) || '';
formatDateToSubmit: function (date) {
return Ext.isDate(date) ? date.dateFormat('H:i') : date;

27 Oct 2010, 6:07 AM
Merci, laurentParis

27 Oct 2010, 12:14 PM
There is a problem with this.
If I do alert(form.findField('time').getValue()) before the form submit, I get the value in the desired format('H:i').
But when the form gets submitted and I fetch the time field's value on the server, it is in the old 'g:i a' format.

How can I make it submit in a format different from what it displayed?

27 Oct 2010, 11:59 PM
If you use standard submit, I suggest to handler beforesubmit event -> modify datetime dom value

28 Oct 2010, 12:05 AM
I solved this by creating a hiden field and setting it's value to the 24-hr format before submit.