namco
namco

Reputation: 155

event remove from full calendar

I've tried this code but it shows JS error.

eventDragStop: function(event) {
    console.log(event);
    console.log(event._id);
    let eve = event.jsEvent;
    //console.log(eve);
    var trashEl = jQuery('#CalendarTrash');
    var ofs = trashEl.offset();

    var x1 = ofs.left;
    var x2 = ofs.left + trashEl.outerWidth(true);
    var y1 = ofs.top;
    var y2 = ofs.top + trashEl.outerHeight(true);

    if (eve.pageX >= x1 && eve.pageX <= x2 &&
        eve.pageY >= y1 && eve.pageY <= y2) {
        if (confirm("Are you sure to  detete " + event.title + " ?")) {
            //pour annuker les informations
            $('#calendar').FullCalendar('removeEvents', event._id);
        }
    }
}

It shows error

Uncaught TypeError: $(...).FullCalendar is not a function

, event.title and event._id are blank everything else is working fine.

As per documentation it has https://fullcalendar.io/docs/v3/removeEvents it has

.fullCalendar( ‘removeEvents’ [, idOrFilter ] )

and this fullCalendar is deprecated as per this documentation https://fullcalendar.io/docs/upgrading-from-v3 now i need the syntax to remove the event on eventDragStop

Upvotes: 0

Views: 1504

Answers (1)

joarfish
joarfish

Reputation: 344

It seems to me that all you need you can find by looking at the link your provided about how to migrate to fullcalendar-4. There are at least two things you need to change:

  • The parameter passed to your callback for eventDragStop is now an object with { event, jsEvent, view } (as explained here)
  • To remove an event: "retrieve an Event object and then call its remove method:"
var event = calendar.getEventById('a');
event.remove();

Upvotes: 2

Related Questions