Reputation: 23
In the FullCalendar plugin, I need allow selection of days until a day or between dates. I put an example to explain better.
https://codepen.io/stefanmalex/pen/Jjjjgmp
I have an array with disallowed days:
var disallowedDays = ['2019-10-17', '2019-10-23', '2019-10-26']
I added the 'selectAllow' callback:
selectAllow: function (selectInfo) {
if (disallowedDays.includes(selectInfo.startStr)) {
return false;
}
return true;
}
This works perfectly if you select day per day, allows selection of all days less disallowed days in array.
PROBLEM: When you select multiple days, it allows select disallowed days. (Example: select from '2019-10-15' to '2019-10-26').
What I need, example: If the selection starts on '2019-10-11', it has to allows you to select until '2019-10-16' because next day ('2019-10-17') is disallowed.
I let the example on codepen. https://codepen.io/stefanmalex/pen/Jjjjgmp
Upvotes: 1
Views: 1535
Reputation: 798
ADyson has recognized it correctly.
The program logic needs to be changed.
In the selectAllow
you were checking the array with startStr, so basically it will be checking with start date of selection only, not the whole selection.
So, if you tried to select 14 oct to 18 oct, you needed to check / compare the disallowed dates with in this range.
So, it is needed to loop through the disallowedDays array to check each date within the tried selection, like the following loop:
for(var i=0;i<disallowedDays.length;i++) {
var dd = new Date(disallowedDays[i]);
if(dd.getTime() >= startDate.getTime() && dd.getTime() <= endDate.getTime()){
return true;
}
}
Following this logic, check here the solution you might be expecting
Upvotes: 3