View Full Version : Getting form from click event in Controller

whirling dervish
18 Jul 2012, 9:51 AM
I am extending the example given in http://docs.sencha.com/architect/2-0/#!/guide/views_forms_extjs to use a more MVC centric approach. So in service of that I want to move the on click handler from the view to a newly create controller.

I have the click even working fine, but I have no idea how to operate on the form from the context of the controller (the view was using this.getForm()).

Here is what I have so far,

Ext.define('LoginExample.controller.LoginController', {
extend: 'Ext.app.Controller',

onLoginButtonClick: function(button, e, options) {
console.log('button clicked');

if (this.getForm().isValid()) {
url: 'login.php',
success: function(form, action) {
Ext.Msg.alert('Login Successful!');
failure: function(form, action) {
Ext.Msg.alert('Login Failed!');

init: function() {
"#loginButton": {
click: this.onLoginButtonClick



Obviously the this in the context of onLoginButtonClick is no longer the view and is instead the controller.

Given the parameters given to me, (Ext.button.Button button, Event e, Object options), how do I get the submit on the appropriate form?

whirling dervish
18 Jul 2012, 10:48 AM
Solved this on stack overflow, http://stackoverflow.com/questions/11547795/getting-form-from-click-event-in-controller-in-extjs.

button.up('form').form will do the trick.