Hi. I have a site where request a booking for a specific period. The request is written to a database using a custom form. In the form there are two date pickers for the "arrival-date" and the "departure-date". I want to make a check that the "departure-date" is at least one past the arrival date. I tried to use code for this, but never used it before so in the end I could not work out how to do this. Does anybody already have a similar check build on their site and can show me what the code looks like?
top of page
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
![feature fixed.png](https://static.wixstatic.com/media/3bfa8a_f845e1016b8a49758acdd6edd6610c3b~mv2.png/v1/crop/x_0,y_2,w_852,h_508/fill/w_104,h_62,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/feature%20fixed.png)
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
bottom of page
Hi All,
Thank you for your suggestions/help/feedback. I have tried all your suggestions, but I think I am not experienced enough to fully understand it and make it work.
So for now I am going to keep the solution that did work and almost does the trick:
$w('#datePicker1').onChange(()=>{
let pickerMinDate = $w("#datePicker1").value;
$w("#datePicker2").minDate = pickerMinDate;
});
The above code ensure that the departure date (datepicker2) is at least equal to the arrival date (datepicker1), because all the dates that are before arrival date cannot be selected in the departure date datepicker.
Hi,
I found this nice documentation for comparing two date objects . I found also this Stackoverflow thread regarding the same question.
Good luck!
Tal.
Tried to do a set/getDate and then +1? Found this on Stackoverflow:
function addDays(date, days) {
var result = new Date(date);
result.setDate(result.getDate() + days);
return result; }
I never did any date transformations, but I believe the problem is here that +1 is ambiguous: +1 what? A millisecond, a second, an hour, a day, a year? So you first have to specify the object (date/day) and then operate on it.
Hi Giri, thanks for your help. Just tried your suggestion. Different error message:
It does not pick up the +1. If I do this without +1 it works fine. Any creative thoughts?
Smells like a type conversion. Could you try instead of:
let pickerMinDate = $w("#datePicker1")+1;
this
let pickerMinDate = $w("#datePicker1").value +1;
Hi Giri,
I have tried the following:
$w.onReady(function () {
//TODO: write your page related code here...
$w('#datePicker1').onChange(()=>{
let pickerMinDate = $w("#datePicker1")+1;
$w("#datePicker2").minDate = pickerMinDate;
});
Any help on how to get this working?
PS the site above is a small test website to test this functionality.
Or another one: the Wix date picker lets you block out dates. So on the departure field, you could block out all dates from arrival date +1
Have you tried doing 'if(departure <= arrival) {do something} on the onBlur of the departure field?