extjstimefield

add 15 minutes to timefield


I use two timefields. One is the starttime and the other the endtime. When i select a time in the starttime i load this value into the endtime:

{
xtype: 'timefield',
flex: 1,
margins: '10',
maxHeight: 25,
maxWidth: 100,
fieldLabel: '',
labelAlign: 'top',
name: 'startTijd',
allowBlank: false,
altFormats: 'G:i',
format: 'G:i',
listeners: {
    change: {
        fn: me.onTimefieldChange,
        scope: me
    }
}

}

This is the function for the listener

onTimefieldChange: function (field, newValue, oldValue, eOpts) {
  Ext.getCmp('eindTijd').setValue(newValue);
}

But what i want is that when i select starttime = 14:00 the endtime will automaticly increase it with one step for the endtime in this case 14:15. I tried to add 15 to the newValue but that will add 15 to the GMT


Solution

  • Ext provides the Ext.Date.add for this kind of manipulations. With your code, that would be something like:

    onTimefieldChange: function (field, newValue, oldValue, eOpts) {
        var convertedValue = Ext.isEmpty(newValue)
            ? null
            : Ext.Date.add(newValue, Ext.Date.MINUTE, 15);
        Ext.getCmp('eindTijd').setValue(convertedValue);
    }