I'm using fullcalendar version 4, and I've added a custom button to 'refresh' the calendar with current information/events.
Here's my button:
customButtons: {
myReloadButton: {
text: 'refresh',
click: function() {
calendar.refetchEvents();
calendar_mini.refetchEvents();
}
}
I have two calendars that I want to refresh as you can see. It works fine, but I notice an issue. When I create a new event, it's added to the calendar as it should. However, if the user clicks the 'refresh' button right afterwards then the just-added event shows up twice once the events are re-loaded. It seems the newly added event was never removed during the refresh.
I have a modal form that opens to gather information for the event. Once the event is saved, here's how I am saving it (via an ajax call). In the success of the ajax, I am adding the event to my calendar with .addEvent()
var location_id = $('#formEventModal #location_id').val();
var saw_by_id= $('#formEventModal #saw_by_id').val();
$.ajax({
url: "ajax_insert.php?table=appointments",
dataType: 'json',
type: "POST",
data: $('#appointmentForm').find(':input').not('.dont_serialize').serialize(),
success: function(response) {
if (response.success) {
//get the inserted id of the appt just added so it can be updated on the stop if needed.
var lastInsertID = response.lastInsertID;
var event_object = {
id: lastInsertID,
location_id: location_id,
resourceId: saw_by_id,
};
calendar.addEvent(event_object);
calendar_mini.addEvent(event_object);
Why is it that the refresh button doesn't remove newly added events?