1. #1
    Sencha User
    Join Date
    Jul 2007
    Location
    Italy
    Posts
    134
    Vote Rating
    0
    fermo111 is on a distinguished road

      0  

    Default Cannot fire click event on Ext.Button

    Cannot fire click event on Ext.Button


    I am trying to fire a click event on a button whose handler was given in the config object.
    This is the code. My goal is to have the handler of the second button called in response of a click on the first button. But it does not work.

    Code:
    <div id='fire-btn'></div>
    <div id='event-btn'></div>
    
    Ext.onReady(function(){
    	fireBtn = new Ext.Button({
    		renderTo: 'fire-btn',
    		text: 'Fire click event',
    		handler: function(){
    			eventBtn.fireEvent('click');
    		}
    	});
    	eventBtn = new Ext.Button({
    		renderTo: 'event-btn',
    		text: 'Event Btn',
    		handler: function(){
    			alert('ok');
    		}
    	});
    });
    Thanks

    Luca

  2. #2
    Ext User santosh.rajan's Avatar
    Join Date
    Sep 2007
    Location
    Kannur, Kerala, India
    Posts
    611
    Vote Rating
    0
    santosh.rajan is on a distinguished road

      0  

    Default


    Define "var eventBtn = ..."
    Make everything as simple as possible, but not simpler.
    - Albert Einstein

  3. #3
    Sencha User
    Join Date
    Jul 2007
    Location
    Italy
    Posts
    134
    Vote Rating
    0
    fermo111 is on a distinguished road

      0  

    Default


    Quote Originally Posted by santosh.rajan View Post
    Define "var eventBtn = ..."
    That is not the reason. I think it has to do with the fact that the 'handler' function is not registered as an event handler for the 'click' event on the Ext.Button

  4. #4
    Ext User santosh.rajan's Avatar
    Join Date
    Sep 2007
    Location
    Kannur, Kerala, India
    Posts
    611
    Vote Rating
    0
    santosh.rajan is on a distinguished road

      0  

    Default


    You are right. This works.

    Code:
     listeners: {click: function() {alert("yep")}},
    Make everything as simple as possible, but not simpler.
    - Albert Einstein

  5. #5
    Sencha User
    Join Date
    Jul 2007
    Location
    Italy
    Posts
    134
    Vote Rating
    0
    fermo111 is on a distinguished road

      0  

    Default


    Quote Originally Posted by santosh.rajan View Post
    You are right. This works.

    Code:
     listeners: {click: function() {alert("yep")}},
    Right. So either this is a bug or the documentation is misleading. Any comment from the Ext developers?

  6. #6
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    3
    tryanDLS is on a distinguished road

      0  

    Default


    Not sure what you think the problem is - the following code works.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>Hello World Window Example</title>
        <link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
     	<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
        <script type="text/javascript" src="../../ext-all.js"></script>
    <script text="text/javascript">
    Ext.onReady(function(){
        var button = new Ext.Button({
    		renderTo:'test',
    		text:'Hello',
    		handler: function() {
    			alert('hello');
    		}
    	});
    });
    </script>
    </head>
    <body>
    <div id="test"></div>
    </body>
    </html>

  7. #7
    Sencha User
    Join Date
    Jul 2007
    Location
    Italy
    Posts
    134
    Vote Rating
    0
    fermo111 is on a distinguished road

      0  

    Default


    I want to call fireEvent('click') on the button and having the handler called. Presently, the handler function is not a real event handler. I think that the documentation seems to indicate that 'handler' is a shortcut for a listener on the click event, but it is not.

  8. #8
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    3
    tryanDLS is on a distinguished road

      0  

    Default


    The documentation is correct. Handler is a shortcut to specifying the listeners config for the click event.

    You can cannot fire the click event from the handler of the click event - that makes no sense. Even it was allowed, you would be in an endless loop.

    You need to think about what you're trying to accomplish. If you want to simulate that the button was clicked, you could call fireevent('click'...) from outside the scope of the button.

  9. #9
    Sencha User
    Join Date
    Jul 2007
    Location
    Italy
    Posts
    134
    Vote Rating
    0
    fermo111 is on a distinguished road

      0  

    Default


    Quote Originally Posted by tryanDLS View Post
    You need to think about what you're trying to accomplish. If you want to simulate that the button was clicked, you could call fireevent('click'...) from outside the scope of the button.
    In fact this is exactly what i want to do, but it does not work. See the example in my first post.

  10. #10
    Ext User santosh.rajan's Avatar
    Join Date
    Sep 2007
    Location
    Kannur, Kerala, India
    Posts
    611
    Vote Rating
    0
    santosh.rajan is on a distinguished road

      0  

    Default


    Let me explain the problem here. If you use fireEvent to fire a buttons click event, the buttons handler function does not handle it. On the other hand the buttons 'on click' event does. In the first example one button is firing the click event of the second button.
    Make everything as simple as possible, but not simpler.
    - Albert Einstein

Thread Participants: 2