How to make past date unselectable in fullcalendar?

前端 未结 15 1229
暗喜
暗喜 2020-12-08 07:46

Problem is, how to disable selectable on PAST DATES in fullcalendar\'s month/week view.

I want to user not allowed to click/select the on past dates.

相关标签:
15条回答
  • 2020-12-08 08:30

    You can combine:

    -hide text by CSS as mentioned in question

    -disable PREV button on current month

    -check date on dayClick/eventDrop etc:

    dayClick: function(date, allDay, jsEvent, view) {
        var now = new Date();
        if (date.setHours(0,0,0,0) < now.setHours(0,0,0,0)){
            alert('test');
        }
        else{
             //do something
        }
    }
    
    0 讨论(0)
  • 2020-12-08 08:31

    This is what I am currently using

    Also added the .add() function so the user cannot add an event at the same hour

    select: function(start, end, jsEvent, view) {
                   if(end.isBefore(moment().add(1,'hour').format())) {
                   $('#calendar').fullCalendar('unselect');
                   return false;
                 }
    
    0 讨论(0)
  • 2020-12-08 08:33

    The old answers to this question are ok...

    However, the official documentation suggests a new, more concise solution:

    First set the day you want to be the lower bound

     var today = new Date().toISOString().slice(0,10);
    

    Then include the range using validRange. Simply omit the end date.

     validRange: {
        start: today
     }
    
    0 讨论(0)
提交回复
热议问题