7 Reeds
7 Reeds

Reputation: 2539

Should Fullcalendar call dateClick AND select events on a single time click?

I am using the following Fullcalendar libs:

"@fullcalendar/bootstrap": "^4.1.0",
"@fullcalendar/core": "^4.1.0",
"@fullcalendar/daygrid": "^4.1.0",
"@fullcalendar/interaction": "^4.1.0",
"@fullcalendar/list": "^4.1.0",
"@fullcalendar/moment": "^4.1.0",
"@fullcalendar/moment-timezone": "^4.1.0",
"@fullcalendar/timegrid": "^4.1.0",

When I initially define the calendar I set the dateClick and select options to point to a function -- the same function. a la:

calendar = new FullCalendar.Calendar(
    document.getElementById("calendar"), {
        'plugins': [
            "interaction",
            "dayGrid",
            "timeGrid",
            "bootstrap",
            "list",
            "moment",
            "momentTimezone"
        ],
        ...
        'dateClick': DateClick_and_Selection,
        'select': DateClick_and_Selection,
        ...

This is "working". My question is about the events that trigger these two actions.

If I am looking at a timeGridDay view and click&drag to select a range of times then ONLY the select function is called -- this is what I expected.

If I just click one time box in the grid then BOTH dateClick and select functions are called -- not what I expected.

Honestly I can't recall if this has been happening all along or if I just noticed it.

Is this new behavior?

Is this normal?

If it is normal then I know that the contents of the info object passed to the functions are different for the two events. I know that I can create two different functions but I am currently guessing that it would be a footrace to see which one triggers first.

Am I doing something wrong? Is there a better way to deal with this?

I tried to create a fiddle but the various fullcalendar libs seem to be order sensitive and I couldn't find the right order.

Ideas?

Upvotes: 0

Views: 2110

Answers (1)

7 Reeds
7 Reeds

Reputation: 2539

The "solution", at least in my case, is to not implement BOTH dateClick and select hooks. If both are implemented then both fire on click events (at least in Month view). Since both are triggered then there is basically a race to see which one finishes last, the date ranges associated with the last event overwrites the first one, again in my case. Your use cases may be different. Thanks to ADyson for helping me think through this in a clearer way.

Upvotes: 3

Related Questions