FullCalendar disable select day if is not allowed in selectAllow callback

走远了吗. 提交于 2020-02-25 09:40:09

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/58266675/fullcalendar-disable-select-day-if-is-not-allowed-in-selectallow-callback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!