Hi Everyone,
Researching the option to disable selection of certain days based on attributes (check boxes) in the listing. The dates should be included in the range, but just not as start/stop option. So people can only select for example, Monday & Friday as start and stop date.
When testing, the Flatpickr calendar has the option to disable dates, however that would avoid people to select them as a range.
My solution for the font-end would be to just use CSS and disable the days for selection with the “pointerEvents” style parameter, so it stays available as range selection.
The Flatpicker calendar is setup in the common.js file inside (Hivepress/assets/js). To disable days for selection you can use the Flatpicker parameter “onDayCreate” to customise the creation of the calendar per element.
The following works with a manual input on the day numbers (1 & 5 for Mo-Fr). As can be seen in below example. Also the available days are coloured.
if (field.data('ranges')) {
var ranges = field.data('ranges');
settings['onDayCreate'] = function (dObj, dStr, fp, dayElem) {
if (dayElem.className.includes('disabled')) {
return;
}
var d = new Date(dayElem.getAttribute("aria-label"));
//Check if current date in current element is monday or friday using the aria-label that stores the full date in the element
if (d.getDay() != 1 && d.getDay() != 5 ) {
dayElem.style.pointerEvents = "none" ;
}else{
dayElem.style.backgroundColor = "#a0cdd9";
dayElem.style.color = "white";
}
and result in this. As you can see range selection works, but people can only click on the coloured fields as intended.
Now my question is;
How how would I best load the data from a checkbox attribute of the current listing. I tried a few different things, but I’m unable to load the data for the custom attribute of the listing. Checkbox on/off state. Something like $listing->get_custom_checkbox_attributes();
So I can map the (7) checkbox states against the week days and use them in the code above.
I realise that this would only fix the front-end side. And a “malicious booker” could override and select the other days. For that checking, I’m thinking we can use a filter to check if the start & stop days are in-line with the available days on the listing config for a booking to to be successful.
Any way hope someone can share some insight in the main question and that is how to load the listing checkbox data into the above function.