I have implemented a pair of linked datetimepickers. The min and maxDate function works fine, but I want to modify it so that even if a user picks in one input a date that is off limit, the other input will not prevent the user from doing so but renew the min or maxDate accordingly. (For instance, if a user picked '10am' and '2pm' and s/he changed to '3pm', the second field will change to say, 4pm.) I'm not sure how I can do that?
The pickers html:
<div class='col-lg-6'>
<div class="form-group">
<div class='input-group date' id='datetimepicker6'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class='col-lg-6'>
<div class="form-group">
<div class='input-group date' id='datetimepicker7'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
The js:
$(function () {
$('#datetimepicker6').datetimepicker();
$('#datetimepicker7').datetimepicker({
//useCurrent: false //Important! See issue #1075
//btw, it is suggested to set useCurrent to false but the picker is not working when it's set to false so I didn't..
});
$("#datetimepicker6").on("dp.change", function (e) {
$('#datetimepicker7').data("DateTimePicker").minDate(e.date);
});
$("#datetimepicker7").on("dp.change", function (e) {
$('#datetimepicker6').data("DateTimePicker").maxDate(e.date);
});
});
EDITED:
I tried something but it doesn't seem relevant:
$(function () {
$('#datetimepicker1').datetimepicker({
format: 'LT'
});
$('#datetimepicker2').datetimepicker({
//useCurrent: false //Important! See issue #1075
format: 'LT'
});
//$("#datetimepicker1").on("dp.change", function (e) {
// $('#datetimepicker2').data("DateTimePicker").minDate(e.date);
//});
//$("#datetimepicker2").on("dp.change", function (e) {
// $('#datetimepicker1').data("DateTimePicker").maxDate(e.date);
//});
});
$('#datetimepicker1').datetimepicker({
//minDate: 0, // to disable past dates (skip if not needed)
onClose: function(selectedDate) {
// Set the minDate of 'to' as the selectedDate of 'from'
$('#datetimepicker2').data("DateTimePicker").minDate(selectedDate);
}
});
$('#datetimepicker2').datetimepicker();