-
11 Dec 2007 5:12 AM #1
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.
ThanksCode:<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'); } }); });
Luca
-
11 Dec 2007 6:07 AM #2
Define "var eventBtn = ..."
Make everything as simple as possible, but not simpler.
- Albert Einstein
-
11 Dec 2007 7:47 AM #3
-
11 Dec 2007 8:27 AM #4
You are right. This works.
Code:listeners: {click: function() {alert("yep")}},Make everything as simple as possible, but not simpler.
- Albert Einstein
-
11 Dec 2007 8:37 AM #5
-
11 Dec 2007 9:23 AM #6
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>Tim Ryan
Read BEFORE posting a question / BEFORE posting a Bug
Use Google to Search - API / Forum
API Doc (4.x | 3.x | 2.x | 1.x) / FAQ / 1.x->2.x Migration Guide / 2.x->3.x Migration Guide
-
11 Dec 2007 9:33 AM #7
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.
-
11 Dec 2007 9:38 AM #8
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.Tim Ryan
Read BEFORE posting a question / BEFORE posting a Bug
Use Google to Search - API / Forum
API Doc (4.x | 3.x | 2.x | 1.x) / FAQ / 1.x->2.x Migration Guide / 2.x->3.x Migration Guide
-
11 Dec 2007 10:03 AM #9
-
11 Dec 2007 6:24 PM #10
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


Reply With Quote