I'm using a bootstrap-datepicker widget.
I have two datepickers on my page, one for start date and one for end date. I need to restrict selecting dates in a way that start date goes after end date and vice versa.
So I'm adding a logic for startDate
and endDate
properties to these datepickers:
$(document).ready(function () {
$('#txtEndDate').datepicker({
startDate: new Date($("#txtStartDate").val()),
orientation: "bottom auto"
});
$('#txtStartDate').datepicker({
endDate: new Date($("#txtEndDate").val()),
orientation: "bottom auto"
});
$('#txtEndDate').change(function() {
$('#txtStartDate').datepicker({
endDate: new Date($(this).val())
});
});
$('#txtStartDate').change(function() {
$('#txtEndDate').datepicker({
startDate: new Date($(this).val())
});
});
});
It works fine only on page load, but if one of the dates is changed and not saved yet, the other datepicker
is not updated immediately according this changes, and I am able to select inappropriate date in it. The available dates in that datepicker
are updated only after i save changes and the whole page refreshes.
What should I add here in order to update available dates in my datepickers
dynamically?