PDA

View Full Version : Update timefield values with current time



rich9285
9 Jul 2013, 4:06 PM
Hi All,

I have a timefield which I want the minValue to be populated with the current time. (so the user cannot schedule a time in the past)

{
xtype: 'timefield',
id: 'id16_scheduleTimeField',
name: 'scheduleTimeField',
fieldLabel: 'Time',
increment: 15,
format: 'G:i',
allowBlank: false,
minValue: Globals.getHours()
invalidCls:null,
},

where

Globals.getHours = function (){
var currentTime = new Date();
var hours = currentTime.getHours().toString();
var min = currentTime.getMinutes().toString();
var time = " ";
if(min <= 9){
time = hours + ":" + "0" + min;
}
else {
var time = hours + ":" + min;
}
return time;
};

However, if I dont refresh the browser then the minValue will still show a time in the past. Is there a way to automatically update the timefield to show only current time or update every 15 minutes?

Thanks,
Rich

asankaub
10 Jul 2013, 1:51 AM
you can write a function in listner and set interval to time to time and set the value to the field.
from task manager you can call time to time.

Ext.TaskManager.start({ run: this.refreshFieldMethod,
interval: 1000
});

slemmon
11 Jul 2013, 1:11 PM
The suggestion from @asankaub seems good for updating your field periodically.
You might also consider setting a validator on the field (or doing a validation once the form is submitted).
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.Time-cfg-validator