Results 1 to 7 of 7

Thread: How to ignore click event of ContentPanel

  1. #1
    Sencha User
    Join Date
    Apr 2011
    Posts
    28

    Default How to ignore click event of ContentPanel

    Suppose I have several objects of the type ContentPanel which are used inside a container with AccordionLayout.
    Each ContentPanel object gets a button at the upper right corner via
    Code:
    contentPanel.getHeader().addTool( new Button("click me") );
    Now, if I click on such a button, this also causes the panel in which the button resides to be selected / expanded. Is there any way to prevent the click event for the contentPanel if the button is clicked?

    Thanks for your help!

  2. #2
    Sencha User
    Join Date
    Apr 2011
    Posts
    28

    Default

    btw: calling the stopEvent() method of the event did not work.
    The onClick method of the content panel is still called.

  3. #3
    Sencha User
    Join Date
    Apr 2011
    Posts
    28

    Default

    using the method stopEvent in the onClick method of the button would work like

    Code:
    protected void onClick(ComponentEvent ce) {
      ce.stopEvent();
      super.onClick( ce );
    }
    But not every component has the onClick method. For example if a combo box or a GWT Anchor is used instead, this solution is not possible.

  4. #4
    Sencha User
    Join Date
    Jun 2011
    Location
    Iasi, Romania
    Posts
    144

    Default

    why don't you just disable the buttons from the panels which are not focused .. and enable them only when it becomes focused ?

  5. #5
    Sencha User
    Join Date
    Apr 2011
    Posts
    28

    Default

    Quote Originally Posted by catalin.ciobanu View Post
    why don't you just disable the buttons from the panels which are not focused .. and enable them only when it becomes focused ?
    This could be an option.
    However, this is not exactly the desired behavior. The element (button, anchor whatever) should be clickable - no matter if the panel is the selected one or not, and, as I said, panels which are not the selected one must not be suddenly selected just by clicking the added element.

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

    Default

    Quote Originally Posted by altmayer View Post
    using the method stopEvent in the onClick method of the button would work like

    Code:
    protected void onClick(ComponentEvent ce) {
      ce.stopEvent();
      super.onClick( ce );
    }
    But not every component has the onClick method. For example if a combo box or a GWT Anchor is used instead, this solution is not possible.
    If that works than this works too:
    Code:
    button.addListener(Events.OnClick, new Listener<ButtonEvent>() {
      public void handleEvent(ButtonEvent be) {
        be.cancelBubble();
      }
    });

  7. #7
    Sencha User
    Join Date
    Apr 2011
    Posts
    28

    Default

    You are right. It works as expected. At the beginning I used addSelectionListener instead of addListener which did not produce the desired behavior.

    For an gwt element like Anchor I am using
    Code:
    anchor.addClickHandler( new ClickHandler() {
            @Override
            public void onClick( ClickEvent event ) {
              event.stopPropagation();
              
            }
          });
    Thanks a lot.
    Last edited by altmayer; 19 Jul 2011 at 3:19 AM. Reason: unnecessary code line

Posting Permissions

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