Please check the code below.
I cannot figure out why, when I change the date value in datePickerCheckInPR to a date that is later than the value of datePickerCheckOutPR, datePickerCheckOutPR does not show an invalid state.
However if I change the date value in datePickerCheckOutPR to a value that is earlier than the one of datePickerCheckInPR, it works.
In other words, calling $w(“#datePickerCheckOutPR”).updateValidityIndication() in datePickerCheckInPR_change(…) does not run the customValidation closure defined for that DatePicker in $w.onReady(…).
Please let me know whether I am missing something or if it’s a bug. If the latter, please let me know if you have a workaround to suggest.
My site name is villametisse
Thanks much in advance for your help.
Ben
$w.onReady(function () {
//TODO: write your page related code here…
var date = new Date();
date.setFullYear($w("#datePickerCheckInPR").value.getFullYear());
date.setMonth($w("#datePickerCheckInPR").value.getMonth());
date.setDate($w("#datePickerCheckInPR").value.getDate() + 1);
$w("#datePickerCheckOutPR").value = date;
$w("#datePickerCheckOutPR").onCustomValidation((value, reject) => {
console.log("CHECKING VALIDITY OF DATEPICKERCHECKOUTPR");
if (isDateEarlierOrEqual($w("#datePickerCheckOutPR").value, $w("#datePickerCheckInPR").value)) {
reject("");
}
});
});
export function datePickerCheckInPR_change(event, $w) {
//Add your code for this event here:
$w(“#datePickerCheckOutPR”).updateValidityIndication();
}
function isDateEarlierOrEqual(myDate, dateToCompareWith) {
/*console.log(dateToCompareWith.getDate());
console.log(dateToCompareWith.getMonth());
console.log(dateToCompareWith.getFullYear());
console.log(myDate);
console.log(myDate.getDate());
console.log(myDate.getMonth());
console.log(myDate.getFullYear()); */
if ((myDate.getDate() === dateToCompareWith.getDate()) && (myDate.getMonth() === dateToCompareWith.getMonth()) && (myDate.getFullYear() === dateToCompareWith.getFullYear())) {
console.log("All the same");
return true;
}
if (myDate.getFullYear() < dateToCompareWith.getFullYear()) {
console.log("HERE Year < ");
return true;
}
if (myDate.getFullYear() > dateToCompareWith.getFullYear()) {
console.log("Year > ");
return false;
}
//Years are equal
if (myDate.getMonth() < dateToCompareWith.getMonth()) {
console.log("Month < ");
return true;
}
if (myDate.getMonth() > dateToCompareWith.getMonth()) {
console.log("Month > ");
return false;
}
//Months are equal
if (myDate.getDate() <= dateToCompareWith.getDate()) {
console.log("Day <= ");
return true;
}
//console.log(myDate.getDay());
//console.log(dateToCompareWith.getDay());
return false;
}