0

First, I've seen this: Fullcalendar V4 - clear all events

But the docs for 'remove()' say: Removes all events associated with this source and prevents it from being fetched again.

If I do this:

$("#possibleStaff").on('change', function(){
    var sources = calendaring.calendar.getEventSources();
    sources[0].remove();
    calendaring.calendar.refetchEvents();
});

The refetchEvents is ignored.

Is there a clear everything without removing the source command?

The particular problem I'm trying to work around is if I add an event and then refetchEvents, the added event is still present until I completely reload the page. That's why I'm looking for a 'clear-all'.

Current work around:

calendaring.clearAll = function(){
  $.each(calendaring.calendar.getEvents(), function(key, event){
    var thisEvent = calendaring.calendar.getEventById(event.id);
    if(thisEvent) {
      thisEvent.remove();
    }
  })
};
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Lee Hinde
  • 1,043
  • 12
  • 13
  • There is no direct function, no. I can think of a couple of other ways to work around it which might be a bit more efficient. But, just quickly, why do you want to clear this independently added event? Does it not get saved to your server before that anyway? – ADyson Nov 07 '19 at 09:23
  • 1
    P.S. you could make your workaround more efficient as well: `calendaring.clearAll = function(){ var events = calendaring.calendar.getEvents(); $.each(events, function(key, event){ event.remove(); } })};` - it's better not to call getEvents() repeatedly, and you don't need to fetch the event again by its ID - you've already got it in `event`, so you can just remove it directly. – ADyson Nov 07 '19 at 09:25

0 Answers0