search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Cancel menu deactivation

Asked by Anonymous
1 month ago.

Clicking on a resource's context menu makes the menu disappear.

What should I do to keep it open?

Comment posted by Dan Letecky [DayPilot]
1 month ago.

Can you please specify the use case? Currently, the context menu hides automatically when you click anywhere on the page, including inactive menu elements (e.g., the header).

Comment posted by Anonymous
1 month ago.

I made a menu with “fake” checkboxes.

On click, I switch icon to get checked/unchecked checkbox and reload the events for the concerned resource.

Answer posted by Dan Letecky [DayPilot]
1 month ago.

To prevent the menu from closing when an item is clicked, you can add an onClick event handler to the items and stop the click event from bubbling:

const menu = new DayPilot.Menu({
  items: [
    {
      text: "Item",
      onClick: args => {
        args.originalEvent.stopPropagation();
        // ...
      }
    },
    // ...
  ]
});
Comment posted by Anonymous
1 month ago.

Great!!!

(I tried a ‘args.preventDefault();‘ with no success!)

Thank’s a lot.

Comment posted by Anonymous
1 month ago.

With args.originalEvent.stopPropagation() the menu does’nt refresh.

I found a solution but the menu makes a step to right?

Here is my solution:

menu = new DayPilot.Menu({
    items: [
        {
            text: 'test',
            icon: 'far fa-square',
            onClick: function (args) {
                args.originalEvent.stopPropagation();
                var isChecked = args.item.icon == 'far fa-check-square';
                args.item.icon = isChecked ? 'far fa-square' : 'far fa-check-square';
                menu.show(args.source);
            }
        }
    ],
    onShow: function(args) {
    ...
    }
});
Comment posted by Dan Letecky [DayPilot]
1 month ago.

In the latest sandbox build (2024.4.6226), there is now a new update() method available that lets you refresh the context menu content.

Also, calling args.preventDefault() in onClick handler of a menu item prevents the menu from hiding.

With this build, you can use this:

onClick: function (args) {
    args.preventDefault();
    var isChecked = args.item.icon == 'far fa-check-square';
    args.item.icon = isChecked ? 'far fa-square' : 'far fa-check-square';
    menu.update();
}
Comment posted by Anonymous
1 month ago.

Thanks for your answer!

Finally, I will use DayPilot.Modal.

It will be less clean but functional.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.