Search code examples
javascriptfullcalendarmomentjsfullcalendar-3

Fullcalendar - Need event to not be more than a day - using selectAllow but issue with allDay


I'm using Fullcalendar and need events to not be more than a day.

I've got it working for when you pick an hour range but it never works for allDay events, as the from and to dates are different. Here is my selectAllow function. I'm aware it's not elegant, my Javascript is limited!

function(selectInfo) { 
    var ambig = selectInfo.start._ambigTime;
    var from_date = selectInfo.start._d;
    from_date = String(from_date).substr(0, 10);
    var to_date = selectInfo.end._d;
    to_date = String(to_date).substr(0, 10);

    if (from_date != to_date)
    {
        return false;
    }
    else
    {
        return true;
    }
    var duration = moment.duration(selectInfo.end.diff(selectInfo.start));
    console.log(duration.asHours());
}

As you can see from the code, I've gone down the route of having different checks based on ambigTime (I assume this is whether it's allDay or not?) and using the duration but the duration doesn't work when it's all day.

Any help much appreciated.


Solution

  • Actually you can solve this much more neatly and simply by using selectConstraint. This limits the user's selection to a certain window of time. By specifying it as per the following example, it effectively limits an individual selection to the day where the selection began:

    selectConstraint: {
      start: '00:00', 
      end: '24:00', 
    },
    

    Demo: http://jsfiddle.net/9qv5xz18/