I have 2 timepickers where the first one is for start time and the second one is for end time.
I want that the end time should not exceed the start time. I don't want any default value to be set, also at the very beginning when the user clicks on the start time, the end time should be populated with +2 hours. And then the user can change the end time and can keep it to the minimum of the start time but not below that.
I am using bootstrap timepicker from source
This is what I have worked out:
I disable the end time in the beginning.
$('#end_time_input').prop('disabled', true);
$('#start_time').datetimepicker({
format: 'HH:mm',
useCurrent: false,
});
$('#end_time').datetimepicker({
format: 'HH:mm',
});
$("#start_time").on("dp.change", function (e) {
$('#end_time_input').prop('disabled', false);
var date = e.date;
var d1 = new Date();
d1.setHours(+date._d.getHours()+2 );
d1.setMinutes(date._d.getMinutes());
$("#heure_de_rdv_end_input").val(d1.getHours()+":"+d1.getMinutes());
var start_date = e.date;
var start_hours = date._d.getHours();
var start_mins = date._d.getMinutes();
$('#end_time').data("DateTimePicker").minDate(moment({h:start_hours,m :start_mins}));
});
This doesn't work when increasing the time and also on the first click. Also there are many minor issues in it.