-
1 May 2012 4:05 AM #1
Unanswered: Event handling in MVC text fields?
Unanswered: Event handling in MVC text fields?
I am unclear on the preferred method of event handling when trying to apply an MVC model. The button examples show a button configured like this:
View item:
Controller code:Code:{ text: 'Save', action: 'save' }
Which matches the concept of pushing all logic out of the view into the controller. The text field examples, however, look like this, with everything in the view:Code:'useredit button[action=save]': { click: this.updateUser }
This lets you handle the different events differently, but leaves teh code in the view. Is this accepted practice? One of my developers has tried this approach for text fields, but I am not sure I am comfortable with it:Code:{ fieldLabel: 'Field 2', name: 'field2', listeners: { specialkey: function(field, e) { if( e.getKey() == e.ENTER) { var form = field.up('form').getForm(); form.submit(); } } }
View item:
Controller code:Code:{ xtype: 'textfield', fieldLabel: 'Phone', name: 'phone', itemId: 'phone', action: 'hitEnter' }
In a related question, I have not found documentation on exactly how you specify actions. Can you just put in any string and use it as in the example above?Code:{ 'targetForm textfield[action=hitEnter]' : { specialkey: this.hitEnter }
Thanks. I am a newbie on ExtJS, so no reply is too basic.
- GardnerLast edited by jratcliff; 17 May 2012 at 5:47 PM. Reason: added code tags
-
1 May 2012 5:34 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,637
- Vote Rating
- 435
- Answers
- 3106
We don't force people to use MVC so you can use listeners on the view itself but all those listeners are available to be listened to in the controller.
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.
-
1 May 2012 6:22 AM #3
Mitchell,
Thanks for the reply, but I am not sure if you mean that they last code example is the preferred method, or if we should explicitly have some sort of listener code in the controller. Is the "action" keyword in the view what we are supposed to do for all events in MVC?
A code fragment would probably be helpful.
- Gardner
-
17 May 2012 4:34 PM #4Sencha - Support Team
- Join Date
- Jul 2010
- Location
- Houston, Tx
- Posts
- 7,185
- Vote Rating
- 194
- Answers
- 433
MVC is for you to organize your code. If you want to use the MVC convention, then use the controller for your event handling to maintain our pattern.
This does not mean you are forced to and can certainly place a listener in your view if you prefer.
Regards,
Scott.
-
19 Sep 2012 3:30 PM #5Sencha Premium Member
- Join Date
- Jun 2012
- Location
- San Jose, California
- Posts
- 62
- Vote Rating
- 0
- Answers
- 1
Looking for more examples in MVC event handling in ExtJS 4
Looking for more examples in MVC event handling in ExtJS 4
Does anyone have examples on this? I have multiple pages. How do I pass an event to the controller level and how one page listens to another page's event?
Thanks,
nhan


Reply With Quote