Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot read property 'hasTime' of undefined

I'm using FullCalendar to display staff hours on a Calendar.

I'm pulling the events via an ajax call like so:

"events": function(start, end, timezone, callback) {

  //create the data to be sent
  var objectToSend = {
    "start_date": start.format("YYYY-MM-DD"),
    "finish_date": end.format("YYYY-MM-DD"),
  };

  //craft and make the request
  $.ajax({
    url: 'calendar/test',
    data: objectToSend,
    type: 'POST',
    cache: false
  }).done(function(data) {
    //on success call `callback` with the data
    callback(data)
  })
}

This works perfectly fine, however I am getting an error showing in my console "Uncaught TypeError: Cannot read property 'hasTime' of undefined" and that this is coming from fullcalendar.min.js:6.

I'm not very fluent in JavaScript, but my searching suggests that I either haven't provided the right dates or have junk data in there.

As far as I can tell I am providing all the right data. The function generating the data looks like so:

public function test(Request $request) {
  $start_date = Input::get('start_date');
  $finish_date = Input::get('finish_date');

  $shifts = Roster::whereBetween('date', array($start_date, $finish_date)) - > get();

  foreach($shifts as $shift) {
    $start = $shift - > date.
    ' '.$shift - > start_time;
    $finish = $shift - > date.
    ' '.$shift - > finish_time;

    $events[] = array(
      'title' => $shift - > staff - > first_name,
      'start' => Carbon::createFromFormat('Y-m-d H:i:s', $start) - > toDateTimeString(),
      'end' => Carbon::createFromFormat('Y-m-d H:i:s', $finish) - > toDateTimeString(),
      'id' => $shift - > id,
      'allDay' => false
    );
  }

  return json_encode($events);
}

which outputs:

[{"title":"Gemma","start":"2016-02-01 18:00:00","end":"2016-02-01 22:00:00","id":1,"allDay":false},
{"title":"Gemma","start":"2016-01-26 18:00:00","end":"2016-01-26 22:00:00","id":49,"allDay":false}]

Can anyone spot what I am doing wrong? I am simply trying to use this to render my events for the given month.

Edit: output of console.log(data)

It prints out:

[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]

Opening this up I get:

0: Object

Opening this up I get:

allDay: false
end: "2016-02-01 22:00:00"
id: 1
start: "2016-02-01 18:00:00"
title: "Gemma"
like image 711
James Avatar asked Oct 25 '25 23:10

James


1 Answers

It seems to be you are giving to fullCalendar wrong event's parameter,

Try to render some manually events first.

events: [{
  title: 'event1',
  start: '2010-01-01'
}, {
  title: 'event2',
  start: '2010-01-05',
  end: '2010-01-07'
}, {
  title: 'event3',
  start: '2010-01-09T12:30:00',
  allDay: false // will make the time show
}]

After that, make sure your events match with fullCalendar expected params.

like image 91
sebas07be Avatar answered Oct 27 '25 13:10

sebas07be



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!