palAlaa
palAlaa

Reputation: 9878

Remove event after adding it directly to fullCalender

I want to remove event after adding it directly to full calender, when drop the event I add the id to the event object and when click on the event I want to remove the event. I make alert for the id and it alerts correctly but the event doesn't removed event the ajax code is executed and the event is deleted from server side.

The same code works correctly when adding the event and refresh the page then remove the event.

 eventClick: function(event, element) {

            var current = $(this);

            if(confirm('Are you sure from removing the event?')){
                jQuery.ajax({
                    url: url+"delCalEvent",
                    type: "POST",
                    dataType: 'JSON',
                    data:{
                        'eventId':event.id
                    },
                    success:function(result){
                        if(result  == "1"){

                       //what should I do here to remove the event without refreshing the page
                      $('#calendar').fullCalendar('removeEvents', event.id); 


                        }

                    },
                    error: function (request, status, error) {  
                        alert('Error on deleting the event ');
                        revertFunc();
                    }
                });


            } 

        }

Upvotes: 1

Views: 3171

Answers (1)

john 4d5
john 4d5

Reputation: 741

It should work.. But maybe fullcalendar is not getting the right reference.. Try to use one of the methods below to get the object reference:

// get specif event (reference)
var specificEvent = $('#calendar').fullCalendar('clientEvents', event.id);

or

// get last event added (reference)
var clientEvents = $('#calendar').fullCalendar('clientEvents');
var lastEvent = clientEvents[clientEvents.length-1];

then try to use one of the following methods to remove it:

lastEvent.id = '';
lastEvent.start = '';
lastEvent.end = '';
$('#calendar').fullCalendar('updateEvent', lastEvent);

or

$('#calendar').fullCalendar('removeEvents', lastEvent);

Upvotes: 2

Related Questions