I’m still learning, and I think I’ve done my due diligence trying to find a solution to this by searching…
So here’s what we’ve been doing the past several months… And to add some context - We use a date picker field for customers to choose a ‘ready by’ date. As we book up, we manually add the dates to disable so they can’t be selected.
This has been working fine, but… We’ve been booking well ahead lately and it gets to be a lot of badDate variables to manage. I thought it might be easier if there was a way to use date ranges instead of individual dates.
For example, we’re fully booked for April (so, my code sample below is stripped down to keep it brief), but I have close to 30 “let badDate = …” lines.
So, I’m wondering if there’s something I’m missing that would make it possible to define date RANGES (and combine with individual dates, since they can be scattered at times).
Something like (obviously a mock sample):
let badDate8 = new DateRange(2022, 3, 12 : 2022, 3, 30);
Here’s the ‘condensed’ version of what we’ve been doing:
$w.onReady(function () {
// ALWAYS BLOCK TODAY + NEXT 6 DAYS
var today = new Date();
var dd1 = today.getDate();
var dd2 = today.getDate() + 1;
var dd3 = today.getDate() + 2;
var dd4 = today.getDate() + 3;
var dd5 = today.getDate() + 4;
var dd6 = today.getDate() + 5;
var dd7 = today.getDate() + 6;
var mm = today.getMonth();
var yyyy = today.getFullYear();
let badDate1 = new Date(yyyy, mm, dd1);
let badDate2 = new Date(yyyy, mm, dd2);
let badDate3 = new Date(yyyy, mm, dd3);
let badDate4 = new Date(yyyy, mm, dd4);
let badDate5 = new Date(yyyy, mm, dd5);
let badDate6 = new Date(yyyy, mm, dd6);
let badDate7 = new Date(yyyy, mm, dd7);
// MANUAL DATES - BOOKED
let badDate8 = new Date(2022, 3, 12);
let badDate9 = new Date(2022, 3, 13);
.... And so on (this is where it gets lengthy)
// DISABLE THE DATES
$w("#datePicker2").disabledDates = [badDate1,badDate2,badDate3,badDate4,badDate5,badDate6,badDate7,badDate8,badDate9, ... And so on...];
});
Thanks in advance if anyone can offer any advice that might help make this more manageable!