How to make past date unselectable in fullcalendar?

前端 未结 15 1227
暗喜
暗喜 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:09

    No need for a long program, just try this.

    checkout.setMinSelectableDate(Calendar.getInstance().getTime());    
    Calendar.getInstance().getTime() 
    

    Gives us the current date.

    0 讨论(0)
  • 2020-12-08 08:10

    I have been using validRange option.

    validRange: { start: Date.now(), end: Date.now() + (7776000) // sets end dynamically to 90 days after now (86400*90) }

    0 讨论(0)
  • 2020-12-08 08:12

    below is the solution i'm using now:

            select: function(start, end, jsEvent, view) {
                if (moment().diff(start, 'days') > 0) {
                    $('#calendar').fullCalendar('unselect');
                    // or display some sort of alert
                    return false;
                }
    
    0 讨论(0)
  • 2020-12-08 08:13

    if any one of answer is not work for you please try this i hope its work for you.

     select: function(start, end, allDay) {                
    
                  var check = formatDate(start.startStr);
                  var today = formatDate(new Date());
    
                  if(check < today)
                  {
                     console.log('past');                     
                  }
                  else
                  {                    
                    console.log('future');
                  }
    }
    

    and also create function for date format as below

    function formatDate(date) {
          var d = new Date(date),
              month = '' + (d.getMonth() + 1),
              day = '' + d.getDate(),
              year = d.getFullYear();
    
          if (month.length < 2) month = '0' + month;
          if (day.length < 2) day = '0' + day;
    
          return [year, month, day].join('-');
      }
    

    i have tried all above question but not work for me

    you can try this if any other answer work for you.

    thanks

    0 讨论(0)
  • 2020-12-08 08:17

    Thanks to this answer, I've found the solution below:

    $('#full-calendar').fullCalendar({
        selectable: true,
        selectConstraint: {
            start: $.fullCalendar.moment().subtract(1, 'days'),
            end: $.fullCalendar.moment().startOf('month').add(1, 'month')
        }
    });
    
    0 讨论(0)
  • 2020-12-08 08:23

    In FullCalendar v3.0, there is the property selectAllow:

    selectAllow: function(info) {
        if (info.start.isBefore(moment()))
            return false;
        return true;          
    }
    
    0 讨论(0)
提交回复
热议问题