禁止在周末创建活动 [英] Disable event creation on Weekends
本文介绍了禁止在周末创建活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图将Fullcalendar用于我的一个请假申请中.我启用了选择选项,以便用户可以选择日期并在其上申请休假.但是我想禁止选择周末,即当用户单击周末时它应该发出警报.可以实现吗?
I am trying to use Fullcalendar for one of my leave application. I have select option enabled so that the user can select dates and apply leave on it. But I want to disable weekends from getting selected, ie it should give a alert when the user clicks on the weekends. Is it achivable?
我的代码
this.calendarOptions = {
height:450,
defaultDate: moment(new Date(),'YYYY-MM-DD'),
editable: false,
stick:true,
selectable:true,
eventLimit: false, // allow "more" link when too many events
events: this.eventList,
header: {
left: 'month basicWeek basicDay',
center: 'title',
right: 'today prev,next'
},
displayEventTime: false,
select: (start, end, allDay) => {
this.startDate=moment(start).format("YYYY-MM-DD");
this.endDate=moment(end).format("YYYY-MM-DD");
$('.first.modal').modal('show');
},
dayRender: (date, cell)=> {
//logic
},
selectOverlap:false,
};
推荐答案
您可以在select
方法上执行此操作.只需从startDate到endDate,然后检查其中是否有任何周末.
如果是这样,则显示警报/弹出窗口并返回false.
You can do that on the select
method. Just go from the startDate to the endDate and check if any of those days are weekends.
If so, display the alert / popup and return false.
select: (start, end, allDay) => {
var startDate = moment(start),
endDate = moment(end),
date = startDate.clone(),
isWeekend = false;
while (date.isBefore(endDate)) {
if (date.isoWeekday() == 6 || date.isoWeekday() == 7) {
isWeekend = true;
}
date.add(1, 'day');
}
if (isWeekend) {
alert('can\'t add event - weekend');
return false;
}
this.startDate= startDate.format("YYYY-MM-DD");
this.endDate= endDate.format("YYYY-MM-DD");
//$('.first.modal').modal('show');
},
请参见小提琴.
这篇关于禁止在周末创建活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文