Results 1 to 2 of 2

Thread: How to Remove a Listener?

  1. #1

    Question How to Remove a Listener?

    I've seen lots of references to this, but I can't find any clear example of how this should work. I have a toolbar that I'm populating with a set of buttons performing default actions. The toolbar will be made available to multiple apps that may need to redefine the handler for any given button.

    As far as I can tell, the only way to do so (in theory) is to remove the existing listener and add a new listener. I can add a new listener just fine, but I can't find the right voodoo to apply to remove the default listener.

    I have this:

    Code:
    var tb  = new Ext.Toolbar({
        height: 30,
        width: 'auto',
        items: [
            {
                text: 'A Default Button',
                id: 'toolbar-button-default',
                handler: do_default_thing
            }
        ]
    });
    After the toolbar is rendered, I have the following code in a later js include file:

    Code:
    btn = tb.findById( 'toolbar-button-default' );
    // btn.addListener( 'click', do_custom_thing );
    btn.removeListener( 'click', do_default_thing );
    Is the function handler not the same even though it's referencing the old function directly? If not, what do I need to do to make it operate as expected? Is there a way to do this with anonymous functions? Ideally, I'd like to set the handler to an anonymous function for clarity, but I thought it would be easier to reference a standalone function for removal.

    Much appreciated.

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    The handler, in this case is different from a listener. If you have a peek at the source you'll see that the handler and listeners are fired off one after the other.

    Check out the setHandler method instead.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

Posting Permissions

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