Hi, I'm using a full calendar with Angular and I want to make it so that when the user clicks on an empty schedule in the calendar (it's a weekly calendar with 15 minute intervals for each date), they can' Hold down the click and define the duration of the event. Unfortunately, chatpgt cannot help me in this case because it only shows information as of 2020 and the library is still being updated to this day.
This is my html code:
<div class='demo-app'> <div class='demo-app-main'> <full-calendar *ngIf='calendarVisible' [options]='calendarOptions' > <ng-template #eventContent let-arg> <b>{{ arg.timeText }}</b> <i>{{ arg.event.title }}</i> </ng-template> </full-calendar> </div> </div> </div>
This is my .ts calendarOptions definition:
calendarOptions: CalendarOptions = { plugins: [ interactionPlugin, dayGridPlugin, timeGridPlugin, listPlugin, ], headerToolbar: { left: 'prev,next today', center: 'title', right: 'timeGridWeek' }, initialView: 'timeGridWeek', slotMinTime: '08:00:00', slotMaxTime: '21:00:00', slotDuration: '00:15:00', slotLabelInterval: '00:15:00', slotLabelFormat: { hour: '2-digit', minute: '2-digit', hour12: true, }, contentHeight: 'auto', aspectRatio: 1.5, firstDay: 1, weekends: true, editable: false, selectable: false, selectMirror: true, dayMaxEvents: true, allDaySlot: false, dayHeaderFormat: { weekday: 'short', day: '2-digit', month: '2-digit' }, locales: [esLocale], businessHours: { daysOfWeek: [0, 1, 2, 3, 4, 5, 6], startTime: '09:00', endTime: '21:00', }, select: this.handleDateSelect.bind(this), eventClick: this.handleEventClick.bind(this), eventsSet: this.handleEvents.bind(this), datesSet: this.handleDatesSet.bind(this) };
P粉6681466362023-09-16 11:20:53
So to fix this, like @ADyson said, just add the selectAllow attribute to your calendarOptions object: selectAllow: this.handleDragEvent.bind(this)
//您的其他属性... selectAllow: this.handleDragEvent.bind(this) // ....
Then, add the function in your class, my function verifies if the duration of the new event is more than 15 minutes, if your calendar has a different time interval, set the difference to that time interval
handleDragEvent(selectInfo: DateSelectArg): boolean { const diffInMilliseconds = Math.abs(selectInfo.end.getTime()- selectInfo.start.getTime()); const diffInMinutes = Math.floor(diffInMilliseconds / (1000 * 60)); return diffInMinutes <= 15; }