Results 1 to 9 of 9

Thread: Stopping Event Propagation

  1. #1
    Sencha User
    Join Date
    Nov 2008
    Posts
    23

    Default Stopping Event Propagation

    I have nested panels like ContentPanel B is added to ContentPanel A

    Both the panels are registered with event listeners.

    panelA.addListener(Events.OnClick, eventHandler);

    panelB.addListener(Events.OnClick, eventHandler);

    The eventHandler class contains the handleEvent method

    publicvoid handleEvent(BaseEvent domEvent) {
    }

    If I click Panel B, I get two events fired. One for Panel B and another one for Panel A

    I want to stop the event propagating to Panel A as soon as I receive it Panel B

    Please advise. I see the cancelBubble only for DomEvent

  2. #2
    Sencha User
    Join Date
    Oct 2010
    Posts
    129

    Default

    Code:
    domEvent.setCancelled(true)

  3. #3
    Sencha User
    Join Date
    Nov 2008
    Posts
    23

    Default

    Quote Originally Posted by blay View Post
    Code:
    domEvent.setCancelled(true)
    It did not work. I still get events from the parent panel A.

    From the docs,

    True to cancel the current operation (defaults to false). Only applies to events that can be cancelled as defined by the object firing the event. Canceling an operation does not stop all listeners from being notified of the event.

  4. #4
    Sencha User
    Join Date
    Nov 2008
    Posts
    23

    Default

    Darrel / sven,

    Could you please kindly look into the issue?.

    I need to understand how to stop the events going to parent panels using BaseEvent.

    This is very critical for our project.

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

    Default

    You can simple replace BaseEvent by DomEvent. ContentPanel is a Container and so fires a ContainerEvent which is a subclass of DomEvent.

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

    Default RESOLVED

    Quote Originally Posted by sven View Post
    You can simple replace BaseEvent by DomEvent. ContentPanel is a Container and so fires a ContainerEvent which is a subclass of DomEvent.
    Thanks Sven for the reply. It works now with cancelBubble. I did try with the handleEvent(DomEvent domEvent) earlier. But it failed for SelectionChangedEvent with the ClassCastException. (I have global event handler for all kinds of events at central place)

    <code>
    java.lang.ClassCastException: com.extjs.gxt.ui.client.event.SelectionChangedEvent cannot be cast to com.extjs.gxt.ui.client.event.DomEvent
    </code>

    I have changed my combo box event type to Event.Select from Event.SelectionChange now. I do not see the ClassCastException anymore.

    Thanks again for your help. I am marking this as RESOLVED now.

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

    Default

    SelectionChangedEvent will not be fired in the sample code you gave us here

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

    Thumbs up RESOLVED

    Sven,

    The problem was resolved with your answer. I was trying to explain why I was using handleEvent(BaseEvent baseEvent) instead of handleEvent(DomEvent domEvent).

    I have one common event handler which registers for events depending upon of the widget type

    button.addListener(Events.OnClick, eventHandler);
    combo.addListener(Events.Select, eventHandler);

    All of my widgets are created at one place using a factory. For combo box, I used Event.SelectionChanged type which resulted in the ClassCastException.

    Now I have changed it to Events.Select and it works fine with your suggestion.

    Thanks again!.

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

    Default

    If you use multiply event types for the same listener than you need to use BaseEvent, but you can do an instanceof check against DomEvent in the listener

Similar Threads

  1. Stop Event propagation ?
    By pbban in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 7 Sep 2017, 6:59 AM
  2. Stop event propagation on 'rowselect' event
    By SCinos in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 19 Feb 2013, 1:58 AM
  3. Event propagation on inhereted component.
    By ValiBOSS in forum Ext 3.x: Help & Discussion
    Replies: 6
    Last Post: 14 Aug 2009, 12:53 PM
  4. Event Propagation
    By danutzdobrescu in forum Ext GWT: Help & Discussion (1.x)
    Replies: 1
    Last Post: 24 Feb 2009, 11:22 AM

Tags for this Thread

Posting Permissions

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