I'm trying to connect 2 datepickers to allow user to choose date range.
I've created code like this:
$(function() {
var dates = $("#fromDate, #toDate").datepicker({
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true,
minDate: new Date(2010, 2 - 1, 2),
onSelect: function(selectedDate) {
var option = this.id == "fromDate" ? "minDate" : "maxDate",
instance = $(this).data("datepicker"),
date = $.datepicker.parseDate(
instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
});
This works fine, but I get weird error: When I select date using first input for a second that datepicker shows date from second one. I think that onSelect functions sets somehow date based on second datepicker.
If first datepicker has date in same month as second this error isn't showing.
How to recreate this behaviour:
- Select '2010-02-05' in first datepicker (after You click on date for a second month and year field change to month and year from second datepicker)
This is my jsFiddle: http://jsfiddle.net/Misiu/TyQSG/1/
How should I change onSelect
function to remove this bug?