Problem/Motivation

When trying to load multiple calendars in one view, only the first instance loads. This is because the jQuery selector is targeting an ID, so it will stop once the first match is found when searching the page for calendars.

Proposed resolution

If we modify the jQuery selector used in the attach functions to include an additional selector that looks for a "unique" class, the selector will grab multiple calendar objects and initialize them:
$("#calendar", '.js-drupal-fullcalendar', context)

This fix will not cause any breaking changes to people already using the current ID selector, but will allow projects to utilize the class if they want to have multiple calendars in one view.

User interface changes

The template was updated to include the class on the base template. This will show an example while not impacting current behavior.

Comments

ammuench created an issue. See original summary.

mingsong’s picture

Hi ammuench, thank you so much for raising this idea and contributing the patch.

I will test it out. Once it is bug free. I am happy to merge it into the Dev branch and get it ready for next release.

  • Mingsong committed 36007b8 on 8.x-2.x
    Issue #3060026 by ammuench, Mingsong: Support Multiple Calendars in One...
mingsong’s picture

Just a minor issue that the jquery select string is incorrect. Jquery only accepts two parameters "jQuery( selector [, context ] )".

mingsong’s picture

Status: Patch (to be ported) » Fixed
jberube’s picture

StatusFileSize
new9.42 KB

I created a patch that does the following:

  1. Fixes the bug in the jQuery selector from the previous patch. Now: $('#calendar, .js-drupal-fullcalendarView', context)
  2. Reduces unnecessary further jQuery queries by using $el = $(this).
  3. Allows each view to have its own view settings. Previously, it would have only used the settings for one view.
  4. Changed the name of the array of events from "fullCalendar" to "entries".
jberube’s picture

StatusFileSize
new8.96 KB

Sorry, I didn't update my dev codebase to the latest for #6. This one is for the latest.

jberube’s picture

StatusFileSize
new8.96 KB

Ok, I made another update. The class name was wrong.

jberube’s picture

Status: Fixed » Needs review
providence_matt’s picture

I was running into an issue where I needed two calendars on one page with different default layouts. One needed to be the month layout and the other needed to be the list layout. The patch in #8 would not apply. Using #8's logic I recreated the patch for the module version 8.x-2.4.

providence_matt’s picture

StatusFileSize
new8.96 KB

Fixed patch in #10.

danflanagan8’s picture

#11 works for 8.x-2.5 as well. It would be great to get this into the next release!

Update: #11 fails to apply to 8.x-2.6, which was released a couple weeks ago so it looks like there's more work before this can get into a release. I'll just stick with 2.5 for now!

  • Mingsong authored 8069ed9 on 9.x-1.x
    Issue #3060026 by jberube, providence_matt, ammuench, Mingsong,...
mingsong’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +9.x-1.x

Thanks all for your patch, testing and feedback.

This feature has been added into the 9.x (8.x-4.3) branch based on the same idea as the patches above.

mandclu’s picture

Just so you're aware, the changes made here effectively changed the API for the FullcalendarViewProcessor, as it broke existing implementations, including the one in Smart Date. By convention it's typically considered best practice to move up a major version in your branch name (e.g. 5.x) when you change APIs like this.

karing’s picture

Status: Reviewed & tested by the community » Closed (outdated)

I believe we can close this as outdated as this feature was added 2y ago. If I'm mistaken please let me know.

Good point @mandclu 👍