FullCalendar - Default Event Duration

I would like to be able to change the default duration for all newly created events.

I am in dayView, and if I just clicking (without dragging & dropping) on ​​the calendar, I get half an hour of the session.

I would like to set it by default for one hour.

Perhaps with this code:

, select: function (startDate, endDate, allDay, jsEvent, view) {
    endDate = new Date(startDate);
    endDate.setHours(endDate.getHours() + 1);
}

This effectively sets a good endDate, but is not visually updated.

half hour selection screenshot


Edit

I'm trying to make the behavior look like Google Calendar: if a user clicks on it, he will select a 1-hour event, but the user can still choose half an hour.

+3
source share
3 answers

Based on one example:

select: function(start, end, allDay) {
    var title = prompt('Event Title:');
    if (title) {
        end = new Date(start);
        end.setHours(end.getHours() + 1);

        calendar.fullCalendar('renderEvent',
        {
        title: title,
        start: start,
        end: end,
        allDay: allDay
        },
        true // make the event "stick"
        );
    }
    calendar.fullCalendar('unselect');
},

Before updating the question:

Something like this should work:

eventClick: function (calEvent, jsEvent, view) {
  calEvent.end = new Date(calEvent.start);
  calEvent.end.setHours(calEvent.start.getHours() + 1);
  $('#calendar').fullCalendar('updateEvent', calEvent);
},
+2

, :

fullcalendar.js slotSelectionMousedown. dates = ... :

    if (cell == origCell && (t.name == "agendaWeek" || t.name == "agendaDay"))
        dates = [
            d1,
            addMinutes(cloneDate(d1), snapMinutes), // calculate minutes depending on selection slot minutes 
            d2,
            addMinutes(cloneDate(d2), snapMinutes + 30)
        ].sort(cmp);
    else
        dates = [
            d1,
            addMinutes(cloneDate(d1), snapMinutes), // calculate minutes depending on selection slot minutes 
            d2,
            addMinutes(cloneDate(d2), snapMinutes)
        ].sort(cmp);

, /, Fullcalendar. , , .

0

FullCalendar select callback reset end , . start end select - moment.js. , , hasTime(), , 30 end ( ):

select: function(start, end) {
    if (end.hasTime()) {
        end.add(30, 'minutes');
    }
}
0

Source: https://habr.com/ru/post/1792771/


All Articles