Emit the input event when changing departure date
It is necessary to detect the change using AlpineJS, for instance.
This commit is contained in:
parent
cabab93aa9
commit
2a5b6df8cf
|
@ -11,6 +11,11 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateDepartureDate(date) {
|
||||||
|
departureDateField.value = date;
|
||||||
|
departureDateField.dispatchEvent(new Event('input', {bubbles: true}));
|
||||||
|
}
|
||||||
|
|
||||||
const minNights = Math.max(1, parseInt(departureDateField.dataset.minNights, 10) || 0);
|
const minNights = Math.max(1, parseInt(departureDateField.dataset.minNights, 10) || 0);
|
||||||
arrivalDate.setUTCDate(arrivalDate.getUTCDate() + minNights);
|
arrivalDate.setUTCDate(arrivalDate.getUTCDate() + minNights);
|
||||||
const minDate = formatDate(arrivalDate);
|
const minDate = formatDate(arrivalDate);
|
||||||
|
@ -19,7 +24,7 @@
|
||||||
const departureDate = new Date(departureDateField.value);
|
const departureDate = new Date(departureDateField.value);
|
||||||
const validDepartureDate = !isNaN(departureDate.getTime())
|
const validDepartureDate = !isNaN(departureDate.getTime())
|
||||||
if (!validDepartureDate || departureDate < arrivalDate) {
|
if (!validDepartureDate || departureDate < arrivalDate) {
|
||||||
departureDateField.value = minDate;
|
updateDepartureDate(minDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxNights = parseInt(departureDateField.dataset.maxNights, 10) || 0;
|
const maxNights = parseInt(departureDateField.dataset.maxNights, 10) || 0;
|
||||||
|
@ -28,7 +33,7 @@
|
||||||
const maxDate = formatDate(arrivalDate);
|
const maxDate = formatDate(arrivalDate);
|
||||||
departureDateField.setAttribute('max', maxDate);
|
departureDateField.setAttribute('max', maxDate);
|
||||||
if (validDepartureDate && departureDate >= arrivalDate) {
|
if (validDepartureDate && departureDate >= arrivalDate) {
|
||||||
departureDateField.value = maxDate;
|
updateDepartureDate(maxDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue