FullCalendar - 如何防止过去发生的事件被拖动
Posted
技术标签:
【中文标题】FullCalendar - 如何防止过去发生的事件被拖动【英文标题】:FullCalendar - how to prevent an Event that occurs in the past from being dragged 【发布时间】:2022-01-04 02:04:48 【问题描述】:我想防止过去发生的事件被拖动。我试过用;
eventConstraint:
start: moment().format('YYYY-MM-DD'),/* This constrains it to today or later */
end: '2100-01-01' // hard coded goodness unfortunately
,
我可以通过以下方式防止将拖到过去的日期:
eventDrop: function(info)
var eventObj = info.event;
var check = moment(eventObj.start).format('YYYY-MM-DD');
var today = moment().format('YYYY-MM-DD');
if(check < today)
revertFunc(); //Put the Event back where it came from
else
//code
,
完整代码:
var calendar = new FullCalendar.Calendar(calendarEl,
firstDay: 0, //Sunday
weekends: true, //Show the weekends
businessHours: // days of week. an array of zero-based day of week integers (0=Sunday)
daysOfWeek: [ 1, 2, 3, 4, 5 ], // Monday - Friday
startTime: '09:00', // a start time
endTime: '17:00', // an end time
,
initialView: 'dayGridMonth',
headerToolbar:
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listMonth'
,
locale: 'en-gb',
selectable: true, // gives ability to select multiple days and then have a callback event when this occurs
buttonIcons: false, // show the prev/next text
weekNumbers: true, // show week numbers
navLinks: true, // can click day/week names to navigate views
editable: true, // can make changes and add changes
dayMaxEvents: true, // allow "more" link when too many events
displayEventEnd: true, // display the end time
eventTimeFormat:
hour: '2-digit',
minute: '2-digit',
,// display time with minutes
eventDisplay: 'block', //Changes an event with start and end times from a list-item to a block
eventConstraint:
start: moment().format('YYYY-MM-DD'),/* This constrains it to today or later */
end: '2100-01-01', // hard coded goodness unfortunately
,
events: responseJson1a,//Populate Event using JSON
【问题讨论】:
【参考方案1】:在 fullCalendar 上定义过去的事件时,将 key editable 设置为 false
events: [
title: 'Business Lunch',
start: '2021-11-03T13:00:00',
constraint: 'businessHours',
editable:false,
,
...
...
]
【讨论】:
您好,谢谢;但是,并不是我想要的。我想要所有事件的约束,所以使用 eventConstraint 不是约束。我已经用完整的代码更新了我的问题。 我想我可以使用“oldEvent”来获取原始开始日期;但是,我找不到如何使用它的示例。以上是关于FullCalendar - 如何防止过去发生的事件被拖动的主要内容,如果未能解决你的问题,请参考以下文章