Our powerful JS Calendar component


Post by sbprot »

Hello,

My calendar is set to the "dayresource" view, and I'm attempting to prevent the creation of new appointments based on certain conditions, including the resource. Specifically, I want to avoid displaying the event on the calendar and prevent the event editor from opening. It appears that using the "beforeAutoCreate" function could be the simplest approach to achieve this.

I need to perform some actions before a new event is created. To accomplish this, I must retrieve the resourceId to determine which column the new event will be created in.

However, when I tried to pass "resourceRecord" (where I can easily find the resourceId) in the function arguments, as mentioned in the documentation, it returns "undefined"...

I have access to the "source" object (DayResourceView), which should allow me to retrieve this information, but when I log it, the "resourceId" field is null...

There must be a way to retrieve the resource on which the event is to be created at that specific moment, right?

Thanks for the help!


Post by tasnim »

Hi,

You should be able to retrieve the resourceRecord like this

    listeners : {
        beforeAutoCreate({ resourceRecord }) {
            console.log(resourceRecord);
        }
    },

This should be working for you. You can also test it here https://bryntum.com/products/calendar/examples/date-resource/

DOCS
https://bryntum.com/products/calendar/docs/api/Calendar/view/Calendar#event-beforeAutoCreate

Best regards,
Tasnim


Post by sbprot »

Hi,

Thanks for you reply but like I said, when I do this resourceRecord is undefined...


Post by alex.l »

How can we reproduce that? Do you see that problem in our demos?
Please post the code to reproduce the issue.

All the best,
Alex


Post by Animal »

Yes, the event is fired from two places, dblclick and the context menu. Context menu was augmented to add that, but the dblclick was not.

https://github.com/bryntum/support/issues/8688

While waiting, you can use

beforeAutoCreate({ source, domEvent }) {
    resourceRecord = source.getResourceRecord(domEvent);
    ...
}

Post by sbprot »

Great, it works, thank you Animal!

Actually, what I'm trying to accomplish is to prevent the auto-creation of an event if a double-click has been performed on certain TimeRanges, based on conditions related to the attributes of the concerned timerange. Maybe there is an easier way to achieve this?


Post by Animal »

Returning false from beforeAutoCreate is the way to do that.

Because I assume that you also want to catch contextmenu creation.

Screenshot 2024-02-27 at 08.40.49.png
Screenshot 2024-02-27 at 08.40.49.png (85.24 KiB) Viewed 259 times

Post by sbprot »

Yes, I understood that to prevent this I had to set a "return false", but what I really want to discuss are the conditions that detect that the new event is on the same slot as a timerange (Preventing the auto-creation of an event during a non-working period estimated in hours (and not in days with "nonWorkingDays").

For example, if I have a timerange set for Wednesday, 02/28, from 10 am to 12 pm, I do not want to be able to auto-create an event during that time. However, I don't want this behavior to apply to ALL my timeranges, but only to those with, for example, a specific attribute.
I'm not sure if I'm being clear enough.


Post by Animal »

The event passes the date that the proposed new EventRecord will start on.

You will have to query the timeRanges store to see if there are any which intersect.


Post Reply