Page 1 of 1

disable Delete on events conditionally

Posted: Wed Apr 27, 2022 11:04 am
by tdset

Hi,

we're using the calendar with day/week/month/timeline (scheduler) mode and would like to conditionally disable the delete function on some events.

Now it's very easy to delete events, and some of these events are important.

Ideally we should either disable the delete function when events are rendered or react to the request of trying to delete an event.

I've conditionally hidden the delete context menu using eventMenu processItems.
But there are many other ways in how an entry can be deleted:

  • via the tooltip delete button
  • via the keyboard

Can you give me some hints on how we can accomplish this?


Re: disable Delete on events conditionally

Posted: Wed Apr 27, 2022 11:37 am
by mats

You will need to hide the various UI elements using our configurations, and for the keyboard option - you can listen to https://bryntum.com/docs/calendar/api/Calendar/view/Calendar#event-beforeEventDelete and return false to veto the deletion.


Re: disable Delete on events conditionally

Posted: Wed Apr 27, 2022 3:44 pm
by tdset

thank you Mats. beforeEventDelete sounds good.

I'm trying to figure it out how to get the event the tooltip is shown on so I can decide if the delete button is shown.
Here's what I have now which obviously doesn't work:

features: {
        eventTooltip : {
            showOn : 'click',
            renderer: data => `
                custom html to show in the tooltip
            `,
            tooltip : {
                tools : {
                    delete: this.eventRecord.status == 'published' ? false : true
                },
            },
        },

thank you for your help


Re: disable Delete on events conditionally

Posted: Thu Apr 28, 2022 9:50 am
by tasnim

To achieve that you can use the beforeShow event.
Here is an example:

const calendar = new Calendar({
    ...
    features : {
        eventTooltip : {
            listeners: {
                beforeShow({ source }) {
                    source.tools.delete = false;
                }
            }
        }
    }
});

Best regards,
Tasnim


Re: disable Delete on events conditionally

Posted: Thu Apr 28, 2022 5:11 pm
by tdset

Thank you, the listener works great. Much appreciated!