If I drop a new event onto the calendar and then immediately try to delete it the whole calendar is cleared.
My code is:
$('#calendar').fullCalendar({
(snip)
eventClick: function(event) {
alert("id = " + event.id );
$('#calendar').fullCalendar( 'removeEvents', event.id );
$.ajax({
type: "POST",
url: "delete.php",
data: "&ID=" + event.id
});
},
(snip)
The javascript alert returns "undefined".
So what is happening is that the default removeEvents behaviour with no id is to clear the calendar.
If I reload the page it works as expected.
Why no event.id value?
Comment #1
Posted on Nov 16, 2010 by Massive PandaHave you changed anything? I cannot see a problem on your page. :)
Comment #2
Posted on Nov 16, 2010 by Swift LionTry this.
Drag an event from the box onto the calendar. Then delete it. You'll see Javascript alert with undefined ID.
I have added some events on November 1st so you will see them all disappear when you delete as above.
Comment #3
Posted on Nov 17, 2010 by Massive PandaNow I got it. According to the doc on
http://arshaw.com/fullcalendar/docs/event_data/Event_Object/
the ID is optional unique identifier. So if you add an event this way, you have to generate the ID on your own.
Comment #4
Posted on Nov 17, 2010 by Swift LionOK, here is the solution.
I was using event.id which was undefined.
BUT event._id works for both existing and newly added events.
The function ended up:
Variable eventID was given the id of the new database record.
in drop:
success: function(newID){ //populate the variable with the new record id returned from add.php eventID = newID ; }
eventClick: function(event, jsEvent, view) { //if we are not deleting, populate the variable with the existing event id if(!eventID){ eventID = event._id; }
$.ajax({
type: "POST",
url: "delete.php",
data: "&ID=" + eventID
});
$('#calendar').fullCalendar( 'removeEvents', event._id );
}
add.php and delete.php are the easiest part of this whole thing, but if anyone is interested in the entire code I am happy to make it available.
I will leave the working calendar at http://hinternet.com.au/projects/calendar/ It is now pretty much finished unless I think of some tweaks. It has been pretty tough going for me pushing my jquery knowledge along. Till now I have generally used demos and modified them to suit.
This involved some real work to make it happen. Hope it helps someone else out.
Comment #5
Posted on Nov 22, 2010 by Helpful Monkeyglad you got this to work. yeah, event.id is a user-specified thing that is unreliable, so the you gotta look at event._id
Comment #6
Posted on Dec 5, 2014 by Grumpy GiraffeI am facing a similar problem.The problem appeared once I turned into FullCalendar v.2.2. Unfortunately in my case event._id does not not solve the issue.The value of event._id is something I cannot understand...it is "_fc2". I am attaching an image,it is a snapshot from chrome dev tools to see foryourself. I do not want to go into more detail...as I may create a separate issue for this problem.
- id.PNG 8.51KB
Status: Done