-
6 Nov 2012 4:06 PM #1
Unanswered: Button handler event not calling function (not firing)
Unanswered: Button handler event not calling function (not firing)
I have a view defined, which contains a form panel, which contains a button.
I have set the "handler" to a function within the class, but it just does not fire.
If I put an inline function into the "handler" declaration, then it works.
I'd sure appreciate some advice!
Code:Ext.define("lmsmobile.view.Login", { extend: 'Ext.form.Panel', alias: 'widget.LoginForm', initialize: function(){ this.callParent(); console.log("Initialising the Login view"); }, requires: [ 'Ext.Toolbar', 'Ext.Img', 'Ext.form.FieldSet', 'Ext.form.Password', 'Ext.Button' ], config: { url: 'CheckLogin.php', baseCls: 'MainPanel', items: [ { xtype: 'image', src: 'resources/images/logo.png', width: 492, height: 90 }, { xtype: 'fieldset', title: 'User Login', instructions: 'Please enter your username and password.', items: [ { xtype: 'textfield', name: 'txtUserName', label: 'User Name:', placeHolder: 'Enter your User Name', required: true }, { xtype: 'passwordfield', name: 'txtPassword', label: 'Password:', placeHolder: 'Enter your password', required: true } ] }, { xtype: 'button', text: 'Login', ui: 'action', id: 'LoginButton', handler: this.onLoginButtonPress, scope: this, }, { xtype: 'button', text: 'Forgot Password' }, { xtype: 'button', text: 'Contact Support' }, { docked: 'bottom', xtype: 'toolbar', title: 'Testing', }, ] }, onLoginButtonPress: function() { console.log("onLoginButtonPress from the view."); //this.fireEvent("LoginButtonPressed", this); } });
-
6 Nov 2012 4:21 PM #2
'this' is window object.
Code:var config={ test:this, buttonConfig:{ test:this } } console.info(config.test); console.info(config.buttonConfig.test);Code:config:{ listeners:{ initialize:function(){ this.down('#LoginButton').setHandler(this.onLoginButtonPress); this.down('#LoginButton').setScope(this); } } }I write English by translator.
-
7 Nov 2012 5:54 AM #3
Thanks. I understand that "this" in that context refers to the window object. However, I have tried all ways, with, or without. That was just defaulted back to the sample code that I was using as an outline.
Whatever I do, the "handler:" does nothing. I was interested in the handler: use, not adding listeners - although I tried that with no success also.
I would appreciate something more specific to the code I posted, if possible.
-
7 Nov 2012 7:33 AM #4
Code:Ext.define("lmsmobile.view.Login", { extend: 'Ext.form.Panel', alias: 'widget.LoginForm', initialize: function(){ this.callParent(); console.log("Initialising the Login view"); /* you can write here as well this.down('#LoginButton').setHandler(this.onLoginButtonPress); this.down('#LoginButton').setScope(this); */ }, requires: [ 'Ext.Toolbar', 'Ext.Img', 'Ext.form.FieldSet', 'Ext.form.Password', 'Ext.Button' ], config: { url: 'CheckLogin.php', baseCls: 'MainPanel', items: [ { xtype: 'image', src: 'resources/images/logo.png', width: 492, height: 90 }, { xtype: 'fieldset', title: 'User Login', instructions: 'Please enter your username and password.', items: [ { xtype: 'textfield', name: 'txtUserName', label: 'User Name:', placeHolder: 'Enter your User Name', required: true }, { xtype: 'passwordfield', name: 'txtPassword', label: 'Password:', placeHolder: 'Enter your password', required: true } ] }, { xtype: 'button', text: 'Login', ui: 'action', id: 'LoginButton' //,handler: this.onLoginButtonPress, //scope: this, }, { xtype: 'button', text: 'Forgot Password' }, { xtype: 'button', text: 'Contact Support' }, { docked: 'bottom', xtype: 'toolbar', title: 'Testing', } ], listeners:{ initialize:function(){ this.down('#LoginButton').setHandler(this.onLoginButtonPress); this.down('#LoginButton').setScope(this); } } }, onLoginButtonPress: function() { console.log("onLoginButtonPress from the view."); //this.fireEvent("LoginButtonPressed", this); } });I write English by translator.
-
7 Nov 2012 7:44 AM #5
Thanks, Haduki. So, from the fact that you're always using the "listeners", do I understand that I can't use the "handler" configuration at all?
I like the idea of setting the handler, and this is intending to raise an event which will be intercepted by a controller.
-
7 Nov 2012 9:13 AM #6
You are able to use hanlder configuration if you can pass the scope(not the scope configuration) correctly .
example:
Code:Ext.application({ launch:function(){ var view=Ext.getCmp('someViewId'); var button= Ext.create('Ext.Button',{ handler:view.OnButtonTap, scope:view }); view.add(button); } })Code:Ext.define("lmsmobile.view.Login", { extend: 'Ext.form.Panel', alias: 'widget.LoginForm', initialize: function(){//<--not listener this.callParent(); console.log("Initialising the Login view"); this.insert(2,{ xtype: 'button', text: 'Login', ui: 'action', id: 'LoginButton' ,handler: this.onLoginButtonPress,//<-- here ,'this' is your LoginForm instance ,not 'window' scope: this, }); }, config:{ items:[ {/*image*/}, {/*fieldset*/}, //<--insert login button here {/*button forgot password*/}, ... ] } ...I write English by translator.
-
8 Nov 2012 6:06 AM #7Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,648
- Vote Rating
- 434
- Answers
- 3107
From this config from OP:
this is of the window so it's not going to be able to find onLoginButtonPress on the lmsmobile.view.Login component.Code:{ xtype: 'button', text: 'Login', ui: 'action', id: 'LoginButton', handler: this.onLoginButtonPress, scope: this, },
I would use the control config to listen for the tap event on that button:
Code:config : { control : { '#LoginButton' : 'onLoginButtonPress' } }Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote