Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FullCalendar v2 error: Uncaught TypeError: Cannot read property 'month' of undefined

I'm using the select callback when adding events. The following code worked in v1 but I'm getting the Uncaught TypeError in v2. When I remove the ajax code there is no error but of course I need to add the new event to the database.

select: function(start, end, jsEvent, view) {
  var title = 'Available';
  var eventData;
  eventData = {
    title: title,
    start: start
  };
  $.ajax({
    type : 'POST',
    url : 'add-event.php',
    data: eventData,
    success : function(data){
      $('#calendar').fullCalendar('renderEvent', {
        id: data.id,
        title: data.title,
        start: data.start,
        start: data.end
      }, true);
      $('#calendar').fullCalendar('unselect');
    },
    error : function(XMLHttpRequest, textStatus, errorThrown) {
    }
  });


},
like image 584
mjim Avatar asked Jun 26 '14 17:06

mjim


2 Answers

Try send startDate and endDate in a format use format() for it.

select: function(start, end, jsEvent, view) {
  var title = 'Available';
  var eventData;
  eventData = {
    title: title,
    start: start
  };
  $.ajax({
    type : 'POST',
    url : 'add-event.php',
    data: eventData,
    success : function(data){
      $('#calendar').fullCalendar('renderEvent', {
        id: data.id,
        title: data.title,
        start: data.start.format(),
        end: data.end.format()
      }, true);
      $('#calendar').fullCalendar('unselect');
    },
    error : function(XMLHttpRequest, textStatus, errorThrown) {
    }
  });


},

You can refer to Momentjs

like image 77
sobingt Avatar answered Sep 28 '22 07:09

sobingt


Please check the event data . Source attribute of your event must be null or not populated. SO before calling

$('#calendar').fullCalendar('renderEvent', event);

You have to be make sure that required attribute of your fullcalendar event must be populated. Here is the link for required and optional fieldfor event object.

http://fullcalendar.io/docs/event_data/Event_Object/

like image 23
Mohit Verma Avatar answered Sep 28 '22 07:09

Mohit Verma