My favorites | Sign in
Project Home Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 713: When deleting new event it doesn't have an id
5 people starred this issue and may be notified of changes. Back to list
Status:  Done
Owner:  ----
Closed:  Nov 2010


Sign in to add a comment
 
Reported by geeky....@gmail.com, Nov 15, 2010
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?

http://hinternet.com.au/projects/calendar/ 
Nov 16, 2010
Project Member #1 althaus.it
Have you changed anything? I cannot see a problem on your page. :)
Nov 16, 2010
#2 geeky....@gmail.com
Try 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.
Nov 17, 2010
Project Member #3 althaus.it
Now 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.
Nov 17, 2010
#4 geeky....@gmail.com
OK, 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.
Nov 21, 2010
Project Member #5 adamrs...@gmail.com
glad you got this to work. yeah, event.id is a user-specified thing that is unreliable, so the you gotta look at event._id
Status: Done
Dec 4, 2014
#6 foryou1...@gmail.com
I 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.5 KB   View   Download
Sign in to add a comment

Powered by Google Project Hosting