-
1 Dec 2011 8:53 AM #1
Answered: Tap event on MessageBox
Answered: Tap event on MessageBox
Hi, i have a little sencha touch 2.0 MVC application. packaged via PhoneGap.
I want a little message box which if touched/clicked will let the do something, lets say a couple of simple alert.
To obtain this i have writed this view :
Code:Ext.define('mytest.view.Windowmsg', { extend: 'Ext.MessageBox', alias: 'widget.windowmsg', title: 'Clickable Message', config: { top:20, html : 'Click Me!', style:" text-align:center;background-color:#822222;color:yellow;position:absolute;bottom:20;left:0;right:0;width:80%;margin-left:10%;text-align:center;", listeners: { tap:function(){ alert ('Hello World!'); alert ('Hello Earth!'); } }, modal:false, hidden:false } });
And in the controller i use this lines of code to add the message box to my panel :
Code:.... var mylittlewindow = Ext.widget('windowmsg'); Ext.Viewport.add(mylittlewindow); ....
The message box is correctly visualized but i am not able to control the tap event related to it, like i thought i was doing with the 'listeners' configuration in the Ext.MessageBox.
My question is : Please, what's the right way to control the tap event on that MessageBox ?
-
Best Answer Posted by mitchellsimoens
Don't put listeners in the config object.
Try something like this:
A side note, in production it is much easier to maintain CSS/SASS than to dig through your javascript files and change the style config on your classes. I would get rid of the style config you have and use the cls config to the CSS name you have for all that styling.Code:Ext.define('mytest.view.Windowmsg', { extend : 'Ext.MessageBox', xtype : 'windowmsg', config: { top : 20, html : 'Click Me!', style : 'text-align:center;background-color:#822222;color:yellow;position:absolute;bottom:20;left:0;right:0;width:80%;margin-left:10%;text-align:center;', modal : false, hidden : false }, initialize: function() { var me = this; me.callParent(); me.getEl().on('tap', me.handleTap, me); }, handleTap: function(e, node, opts) { //scope is of mytest.view.Windowmsg class } });
-
1 Dec 2011 11:09 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,640
- Vote Rating
- 435
- Answers
- 3106
Don't put listeners in the config object.
Try something like this:
A side note, in production it is much easier to maintain CSS/SASS than to dig through your javascript files and change the style config on your classes. I would get rid of the style config you have and use the cls config to the CSS name you have for all that styling.Code:Ext.define('mytest.view.Windowmsg', { extend : 'Ext.MessageBox', xtype : 'windowmsg', config: { top : 20, html : 'Click Me!', style : 'text-align:center;background-color:#822222;color:yellow;position:absolute;bottom:20;left:0;right:0;width:80%;margin-left:10%;text-align:center;', modal : false, hidden : false }, initialize: function() { var me = this; me.callParent(); me.getEl().on('tap', me.handleTap, me); }, handleTap: function(e, node, opts) { //scope is of mytest.view.Windowmsg class } });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.
-
2 Dec 2011 2:50 AM #3
Thanks for your quick answer.
I've tried your code, but nothing happens.
It seems that the 'initialize' function is not called at all.
May be cause of the way i am creating this element ?
In fact as i wrote, in the controller to create the messageBox i do this :
Code:.... var mylittlewindow = Ext.widget('windowmsg'); Ext.Viewport.add(mylittlewindow); ....
-
2 Dec 2011 5:44 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,640
- Vote Rating
- 435
- Answers
- 3106
I did this:
Code:var msg = Ext.create('mytest.view.Windowmsg'); msg.show();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.
-
2 Dec 2011 10:46 PM #5
Oppps...what a stupid.
I wrote initialize function before closing the brace of the view config. Corrected and it works ok.
I've lost some hours, but (hope) i've learned a bit more on sencha touch view and event ..
Thank you Mr.Mitchell


Reply With Quote