Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Disable context menu

  1. #1

    Default Disable context menu

    I'm trying to disable the context menu of a LayoutContainer when it's mask. I see a protected method, "disableContextMenu(boolean)", but it doesn't appear to work. Although it does call "event.preventDefault()" when set, it still calls Component.onRightClick(), which posts the dialog. I'm not sure of this is a bug, and the call to onRightClick should be within the if statement, or whether there is another way to disable a Component's context menu.

    Thanks!
    Brian

  2. #2
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    Default

    You want to disable the native browser contextmenu or a contextmenu you set with component.setContextMenu?

  3. #3

    Default

    Both, actually. I have set a context menu of my own, and when the container it's attached to is masked, I don't want the right click event on that container to do anything. I don't want to post my own context menu, but I also don't want it to default back to posting the browser's context menu.

  4. #4
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    Default

    Add a listener to the Events.ContextMenu event and cancel that. Than your own contextmenu wont be shown. disableContextMenu only disabled the native browser contextmenu.

  5. #5

    Default

    Perfect, thanks!

  6. #6
    Sencha User
    Join Date
    Nov 2010
    Posts
    23

    Default

    I also want to disable a my own context menu on a treepanel.
    I've tried a few variations eg. Listener<BaseEvent>, Listener<Component> and cancelBubble, stopEvent, setCancelled, etc.
    So far no luck.
    Please help.

    Here is one example:
    Code:
    Listener<ComponentEvent> cancelContextMenuListener = new Listener<ComponentEvent>() {
    
                        @Override
                        public void handleEvent(ComponentEvent be) {
                            be.cancelBubble();
                        }
                    };
                    tree.addListener(Events.OnContextMenu, cancelContextMenuListener);

  7. #7
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    Default

    cancleBubble is not cancelling an event, it just stops event bubbling. stopEvent will prevent the default action and also stop bubbling. This way the browser contextmenu should not appear.

  8. #8
    Sencha User
    Join Date
    Nov 2010
    Posts
    23

    Default

    I have changed the code to use stopEvent(), but it's still not working.
    It looks like it is only disabling the native context menu. It is not disabling my custom context menu. How can I achieve that?

  9. #9
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    Default

    Disabling the custom context menu is not linked to any browser event. You need to "cancel" the ContextMenu event.

  10. #10
    Sencha User
    Join Date
    Nov 2010
    Posts
    23

    Default

    Ok, but how?

Page 1 of 2 12 LastLast

Similar Threads

  1. disable a item in the context menu
    By gurusingh in forum Ext 1.x: Help & Discussion
    Replies: 4
    Last Post: 7 Jul 2013, 6:56 PM
  2. Disable the browser context menu
    By Jogilein in forum Ext GWT: Discussion
    Replies: 0
    Last Post: 26 Apr 2010, 4:52 AM
  3. Disable Grid column context menu
    By Spider in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 17 Apr 2007, 4:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •