Disable an entry in contextmenu after clicked

0 Answers 85 Views
Menu
Bernd
Top achievements
Rank 1
Bernd asked on 13 Feb 2023, 10:59 AM

Hello,

i need some help regarding a problem with the context-menu. i am total new with the framework so maybe my question sounds a little stupid. sorry for that. 

When an entry in the context menu is clicked twice (kind of double-click) the app has a problem with the request that is still beeing executed by the first click. 

So how can i disable a context menu-entry inside a click handler. We are using typescript.

The handler starts with 

    private OnMenuItemSelect(event: ContextMenuSelectEvent): boolean {
        const item = $(event.item);
        const menuItemId = this.GetMenuItemIdFrom(item);
        if (menuItemId == null) {
            return true;
        }
        const menuItem = this.GetMenuItemById(menuItemId);
        if (menuItem == null) {
            return true;
        }

 

How can i access the clicked entry and disable it ?

Neli
Telerik team
commented on 16 Feb 2023, 09:10 AM

Hi Bernd,

I am not sure about the exact scenario and ContextMenu configuration on your side. However, as far as I understand you need to disable the default behavior when an item in the ContextMenu is clicked a second time. If this is the issue I would suggest when an item is clicked add a custom class to it. Then if the same item is clicked again to prevent the default behavior. you can also remove the custom class, so in case the same item is clicked again to execute again the logic that is implemented for the 'first click'.

As you will see in the Dojo example linked here when an item is clicked for a first time a message will be logged in the console. When the same item is clicked second time an alert will appear.

 

select: function(e){
          
          if($(e.item).hasClass('clicked')){
              alert('Second click')
              $(e.item).removeClass('clicked')
              e.preventDefault()
            }else{
                console.log('first click')              
                $(e.item).addClass('clicked')
            }
}

 

Regards, Neli

No answers yet. Maybe you can help?

Tags
Menu
Asked by
Bernd
Top achievements
Rank 1
Share this question
or