问题
In my scheduler view, I'm trying to limit the amount of time a user can select to a maximum of 4 hours. I thought that selectConstraint
would be the ticket, but don't see a way to apply a max selectable duration.
I was hoping for something along the lines of selectConstraint: {duration: '04:00'}
or perhaps duration: '240'
(in minutes).
Or... maybe limit the number of selectable slots?? I have it broken up into 15 minute increments, so is there a way to limit the select to a maximum of 16 slots?
I've been scouring the FullCalendar Docs (which is I think is rather poor IMO...), but I can't seem to find the key ingredient.
Anyone?
$('#schedulerCalendar').fullCalendar({
defaultView: 'agendaDay',
defaultDate: moment(systemDate),
eventClick: $scope.eventClick,
editable: true,
eventOverlap: false,
selectable: true,
selectHelper: true,
select: $scope.dayClick,
slotDuration : '00:15:00',
slotEventOverlap: false,
allDaySlot: false,
// Display only business hours (8am to 5pm)
minTime: "08:00",
maxTime: "17:00",
businessHours: {
dow: [ 1, 2, 3, 4, 5], // Monday - Thursday
start: '08:00', // start time (8am)
end: '17:00', // end time (5pm)
},
hiddenDays: [ 0, 6 ], // Hide Sundays and Saturdays
events: function (start, end, timezone, callback) {
callback($scope.eventSources);
},
});
回答1:
You can use fullCalendar's selectAllow and moment duration asHours functions:
$('#schedulerCalendar').fullCalendar({
//....
selectAllow: function(selectInfo) {
var duration = moment.duration(selectInfo.end.diff(selectInfo.start));
return duration.asHours() <= 4;
},
//...
});
来源:https://stackoverflow.com/questions/44552365/fullcalendar-limit-amount-of-selectable-time-in-scheduler