I implemented date range picker logic using the jQUery UI datepickerdatepicker component.
Here is my code:
var onDocumentReady = function () {
var datepickerConfiguration = {
dateFormat: "dd/mm/yy"
};
var startDatepickerHandler = function () {
var selectedDate = $(this).val();
var newConfiguration = Object.create(datepickerConfiguration);
newConfiguration.minDate = moment(selectedDate, "DD/MM/YYYY").toDate();
$("#End").datepicker('destroy');
$("#End").datepicker(newConfiguration);
};
var endDatepickerHandler = function () {
var selectedDate = $(this).val();
var newConfiguration = Object.create(datepickerConfiguration);
newConfiguration.maxDate = moment(selectedDate, "DD/MM/YYYY").toDate();
$("#Start").datepicker('destroy');
$("#Start").datepicker(newConfiguration);
};
///--- Component Binding ---///
$('#Start').datepicker(datepickerConfiguration);
$('#End').datepicker(datepickerConfiguration);
$('#Start').on('change', startDatepickerHandler);
$('#End').on('change', endDatepickerHandler);
};
$(document).ready(onDocumentReady);
But I am not satisfied with this approach of setting the min and max valuevalues of datepickerdatepicker, because in this case, it always destroys and creates a new datepickerdatepicker on every date change, and. It also creates an object for configuration which may cause lot of memory waste. Please tell what would be a better approach of setting the min and max valuevalues of datepickerdatepicker.