PDA

View Full Version : how to show current time in timefield



raj_plays
22 Mar 2014, 3:26 AM
Hi,
My grid has a timefield.
When the editor kicks in I need the timefield to show the current hour.
Using value property did not work.


{
header: "Time",
width: 80,
dataIndex: 'time',
sortable: true,
editor: {
xtype: 'timefield', // rules about editing
allowBlank: false,
minValue: '12:00 AM',
maxValue: '11:00 PM',
increment: 60,
format: 'g:i A',
value: Ext.util.Format.date(new Date(), 'g:00 A'),
style: {
float: 'left'
}
},
align: 'left'
}


Please help.

Kachopsticks
27 Mar 2014, 10:14 AM
The line value: Ext.util.Format.date(new Date(), 'g:00 A') seems to work for me. I am wondering if it is how you are creating your field. When I use the rowEditor I add it to the column which I have promoted to a class. You could try this.



{
header: "Time",
width: 80,
dataIndex: 'time',
sortable: true,
editor: new Ext.form.TextField({ // rules about editing
allowBlank: false,
minValue: '12:00 AM',
maxValue: '11:00 PM',
increment: 60,
format: 'g:i A',
value: Ext.util.Format.date(new Date(), 'g:00 A'),
style: {
float: 'left'
})
},
align: 'left'
}


My other thought is that you could try setting the value of the field after you have created it. So something like myDateField.setValue(Ext.util.Format.date(new Date(), 'g:00 A');