When a date is selected, the user should be able to select another date within a period of one week after the date that he selected. Here's the code I'm using:
$(".datepicker_reservas").datepicker({
minDate: 0,
numberOfMonths: [1,4],
beforeShowDay: function(date) {
var date1 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#datepicker_entrada").val());
var date2 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#datepicker_saida").val());
return [true, date1 && ((date.getTime() == date1.getTime()) || (date2 && date >= date1 && date <= date2)) ? "dp-highlight" : ""];
},
onSelect: function(dateText, inst) {
console.log(dateText);
var date1 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#datepicker_entrada").val());
var date2 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#datepicker_saida").val());
var selectedDate = $.datepicker.parseDate($.datepicker._defaults.dateFormat, dateText);
$( ".datepicker_reservas" ).datepicker( "option", "minDate", dateText);
if (!date1 || date2) {
$("#datepicker_entrada").val(dateText);
$("#datepicker_saida").val("");
$(this).datepicker();
} else if( selectedDate < date1 ) {
$("#datepicker_saida").val( $("#datepicker_entrada").val() );
$("#datepicker_entrada").val( dateText );
$(this).datepicker();
} else {
$("#datepicker_saida").val(dateText);
$(this).datepicker();
}
}
});
I have tried to set maxDate in several ways;
$( ".datepicker_reservas" ).datepicker( "option", "maxDate ", newDate);
$( ".datepicker_reservas" ).datepicker( "option", "maxDate ", '1w');
But maxDate is basing itself on the current date for the seven days. How can I make it use the selected date to set the seven days?