I have rendered multiple calendars on a single page and I need to use the next / prev buttons (as well as date select) in order to see different date ranges. I have connected external next / prev buttons, however, they only effect the last calendar on the page.
My JS to make the calendar elements:
document.addEventListener('DOMContentLoaded', function() {
for (let index = 1; index <= array_length; index++) {
calendar_str = 'calendar_' + String(index);
eval('var ' + calendar_str + ' = document.getElementById(\'' + calendar_str + '\');');
var calendar = new FullCalendar.Calendar(eval('calendar_' + String(index)), {
... code here to setup calendar ...
});
calendar.render();
calendar.setOption('contentHeight', 200);
document.getElementById('prev-btn-ext').addEventListener('click', function() {
calendar.prev(); // call method
});
document.getElementById('next-btn-ext').addEventListener('click', function() {
calendar.next(); // call method
});
}
});
My problem is that when the page is rendered, I can see all of the calendars and I can drag and drop events between them, however, when I click the next and prev buttons only the very last calendar changes. I need all of the calendars to change synchronously based off of the single next / prev button.
As you can see, my calendar instances are named 'calendar_1', 'calendar_2', etc. but the EventListener for the next and previous buttons only looks at the "calendar" variable. I am wondering if my problem has to do with that, maybe I need to specify an argument for calendar.next() or calendar.prev() for each calendar instance somehow?