David Geismar
David Geismar

Reputation: 3422

Cant transform in the right format date & hour from fullcalendar event object

I am using fullcalendar http://fullcalendar.io/. Everytime a user is selecting a timeslot in my calendar, I want to get all events that are in the calendar and transfer them in a hidden field in my view :

 $('#calendar').fullCalendar({

});

I have a select callback :

select: function(start, end, id, allDay) {
var eventData = {
        start: start,
        end: end,
        unique_id: guid(),
        block:  true,
        editable: true,
        backgroundColor: "#469278"
      };
$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true


       var all_events = $('#calendar').fullCalendar('clientEvents');
       $.each(all_events, function(index, value) {
        console.log(value.start["_d"]);
        console.log(index);
           var day         = value.start["_d"].format("dddd");
           var start_time  = value.start["_d"].format("HH:mm");
           var end_time    = value.end["_d"].format("HH:mm");
           var id          = value.unique_id["_i"];
           var slot        = {
              day: day,
              start_time: start_time,
              end_time: end_time,
              id: id
            };
          array_all_events.push(slot);
          $("#dispo_array").val(JSON.stringify(array_all_events));
      });
  $('#calendar').fullCalendar('unselect');
    },

Here I am saying that everytime a user does a select action, I should get all events object :

var all_events = $('#calendar').fullCalendar('clientEvents');

I then iterate on each one of them, transform them into the right format and send them into my hidden field. I don't understand why I get an error on this line :

var day         = value.start["_d"].format("dddd");

Uncaught TypeError: value.start._d.format is not a function

Upvotes: 0

Views: 222

Answers (1)

Guruprasad J Rao
Guruprasad J Rao

Reputation: 29683

.format method is dependent on moment library and hence you should use it as below:

var day = moment(value.start["_d"]).format('dddd')

Same goes with other variables.

Upvotes: 1

Related Questions