0

I am using the jQuery Fullcalendar plugin. On the same page, I have a form with checkboxes which are used to filter the event data fetched from the server. The idea is that I want to pass those form values into the eventSources object, so that they get transmitted to the server together with the start/end timestamps.

The docs have a sample eventSources object like this:

$('#calendar').fullCalendar({
   eventSources: [
     // your event source
      {
        url: '/myfeed',
        type: 'POST',
        data: {
          custom_param1: 'something',
          custom_param2: 'somethingelse'
        },
      }
      // other sources...
   ]
});

Which I modified to:

   eventSources: [
   {
     // ...as above
     data: getFormAsObject(),
     // as above...
   }

I want the form's values to get passed into the the data object. In the getFormAsObject() function, I serialize the form and convert that to an associative array.

All that is left is to hijack the form submission. So if the "submit" button is clicked, I cancel the default POST action, and call

calendar.fullCalendar("refetchEvents");

BUT, this doesn't work, and the getFormAsObject() doesn't get called at all. What am I doing wrong?

5
  • Strangely enough, the function gets called once when the page loads (and the calendar is initialized), but not again after that.
    – Bobby B
    Commented Nov 8, 2012 at 0:54
  • I also tried data: function () { return getFormAsObject(); }, which doesn't trigger it either
    – Bobby B
    Commented Nov 8, 2012 at 0:56
  • not easy to follow sequence of events easily here. Start by addressing if any errors are thrown in console
    – charlietfl
    Commented Nov 8, 2012 at 1:07
  • not enough code here or full sequence description to really follow how app works. For example if you initialize plugin on page load...form elements haven't likely been populated yet
    – charlietfl
    Commented Nov 8, 2012 at 1:28
  • no everything works as described (I think!), and the plugin does work; but it's as if it ignores the data object. I assume I'm passing it wrong.
    – Bobby B
    Commented Nov 8, 2012 at 2:18

2 Answers 2

1

Problem is (it seems) that Fullcalendar only reads that data object once. So it reads it the first time and then not again, even if I set it to a function. I'm not certain, but I think it may be how the underlying ajax() call works?

So I've changed it to remove the eventSources and then readd new ones every time I do an update. Seems ugly, but works.

0

Use the "Dynamic data parameter" Second last option here: https://fullcalendar.io/docs/events-json-feed

$('#calendar').fullCalendar({

  events: {
    url: '/myfeed.php',
    data: function() { // a function that returns an object
      return {
        dynamic_value: Math.random()
      };
    }
  }

});

Not the answer you're looking for? Browse other questions tagged or ask your own question.