0
When a date is selected, the user should be able to select another date within one week after the date 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 of various shapes;
$( ".datepicker_reservas" ).datepicker( "option", "maxDate ", newDate);
$( ".datepicker_reservas" ).datepicker( "option", "maxDate ", '1w');
But maxDate is based on the current date to give the seven days. How can I get it to use the selected date to set the seven days?
Thank you so much for the help, your code was very useful, I’m starting here now, so I don’t know how to formulate the questions right, I forgot to comment that I would need to use only one datepicker, but even so it helped a lot, I used some parts of your code and logic to implement and improve a little more mine. Thank you very much
– Etobdc