javascript 在 FullCalendar 中禁用过去日期的拖放

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33496695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 16:32:46  来源:igfitidea点击:

Disable drop on past dates in FullCalendar

javascriptjqueryfullcalendar

提问by FireDrakon

I started using the FullCalendar plugin recently. I am trying to implement a function on dropping events in the calendar. But before saving to the database, I want to check and disable/prevent dropping external events on dates before today.

我最近开始使用 FullCalendar 插件。我正在尝试实现一个在日历中删除事件的功能。但是在保存到数据库之前,我想检查并禁用/防止在今天之前的日期删除外部事件。

Any idea on how to do this?? I am looking for something like the past days getting greyed-out or something like that so that I can display the events already present as well. Just want to prevent the user from dropping an event on a past date.

关于如何做到这一点的任何想法?我正在寻找类似过去几天变灰或类似的东西,以便我也可以显示已经存在的事件。只是想防止用户在过去的日期删除事件。

EDIT:

编辑:

 drop: function (date, jsEvent, ui) {

     if(date<currentDate) {
         $('#calendar').fullCalendar('removeEvents', event.id);
     }

I tried using this method to remove the dropped event from the calendar and to append it to the div again. Even then, it is not getting removed.

我尝试使用此方法从日历中删除删除的事件并将其再次附加到 div。即便如此,它也不会被删除。

Thanks. :)

谢谢。:)

回答by smcd

eventConstraintcan disable dragging and dropping outside of established boundaries

eventConstraint可以禁止在既定边界之外拖放

To gray out past days

灰白过去的日子

/* SHADE DAYS IN THE PAST */
td.fc-day.fc-past {
    background-color: #EEEEEE;
}

And for eventConstraint

而对于 eventConstraint

        /* This constrains it to today or later */
        eventConstraint: {
            start: moment().format('YYYY-MM-DD'),
            end: '2100-01-01' // hard coded goodness unfortunately
        }

http://jsfiddle.net/1qsrjffL/

http://jsfiddle.net/1qsrjffL/

For the 'end' of eventConstraint, you could add days to the current date if you like vs hard coded

对于 eventConstraint 的“结束”,如果您喜欢与硬编码相比,您可以将天数添加到当前日期

EDIT:

编辑:

To gray out time in the day view you can use businessHours

要在日视图中显示时间,您可以使用 businessHours

businessHours: {
    start: moment().format('HH:mm'), /* Current Hour/Minute 24H format */
    end: '17:00', // 5pm? set to whatever
    dow: [0,1,2,3,4,5,6] // Day of week. If you don't set it, Sat/Sun are gray too
}

Dropping of external events onto the agendaDay in the past isallowed to occur. Editing the eventConstraint to include time will work 'YYYY-MM-DD HH:mm' but it prevents dropping on today in Month view...

外部事件的拖放到过去的agendaDay允许发生。编辑 eventConstraint 以包含时间将起作用 'YYYY-MM-DD HH:mm' 但它可以防止今天在月视图中掉线......

http://jsfiddle.net/1qsrjffL/1/

http://jsfiddle.net/1qsrjffL/1/

回答by Slyvain

eventDropshould get you there:

eventDrop应该让你到达那里:

eventDrop: function(event, delta, revertFunc) {
        if(event.start < currentDate) {
            revertFunc();
        }
    }