suggestion for Datepicker Date Range example
I found it rather odd that the official
Datepicker Date Range example doesn't filter date ranges if default values are provided via HTML, i.e.
- <input type="text" id="from" name="from" value="04/15/2011" />
- ...
(Well, it does work eventually, but not the first time you try selecting a date after the page loads - it lets you select anything. The date range filter is only applied after the onSelect function is called).
I could be wrong, but I imagine there has to be quite a few people using the date range example who also expect it to work when providing a default value via HTML.
Anyway...here's what I ended up with. It filters the dates before and after a date is selected on either side.
- var dates = $('#StartDate, #DueDate').datepicker({
numberOfMonths: 3,
beforeShow: function(selectedDate) {
var opposite = this.id == 'StartDate' ? 'maxDate' : 'minDate';
$(this).datepicker('option', opposite, dates.not(this).datepicker('getDate'));
},
onSelect: function(selectedDate) {
var option = this.id == 'StartDate' ? 'minDate' : 'maxDate';
dates.not(this).datepicker('option', option, $(this).datepicker('getDate'));
}
});
Works for me. Is that something you might want to update the example with?