2012-03-13 10 views
6

Tengo una aplicación Sencha Touch 2 MVC con un formulario a modo de vista. Estoy tratando de obtener sus valores del controlador sin éxito.Sencha Touch 2 - ¿Cómo obtener los valores de formulario?

¿Cómo se pudo hacer esto? Estoy publicando mi código de vista/controlador para este.

Vista:

Ext.define('MyApp.view.LoginForm', { 
    extend: 'Ext.form.Panel', 
    config: { 
     fullscreen: true, 
     items: [ 
      { 
       xtype: 'fieldset', 
       title: 'Login', 
       id: 'loginform', 
       items: [ 
        { 
         xtype: 'emailfield', 
         name: 'email', 
         label: 'Email' 
        }, 
        { 
         xtype: 'passwordfield', 
         name: 'password', 
         label: 'Password' 
        } 
       ] 
      }, 
      { 
       xtype: 'button', 
       width: '50%', 
       text: 'Login', 
       ui: 'confirm', 
       id: 'btnSubmitLogin' 
      }, 
      { 
       xtype: 'toolbar', 
       docked: 'top', 
       title: 'MyApp Mobile' 
      } 
     ] 
    } 
}); 

y el controlador:

Ext.define("MyApp.controller.LoginForm", { 
    extend: "Ext.app.Controller", 
    config: { 
     refs: { 
      btnSubmitLogin: "#btnSubmitLogin" 
     }, 
     control: { 
      btnSubmitLogin: { 
       tap: "onSubmitLogin" 
      } 
     } 
    }, 
    onSubmitLogin: function() { 
     console.log("onSubmitLogin"); 
     var values = app.views.LoginForm.loginform.getValues(); 
     TryLogin(values['email'], values['password']); 
    }, 
    launch: function() { 
     this.callParent(); 
     console.log("LoginForm launch"); 
    }, 
    init: function() { 
     this.callParent(); 
     console.log("LoginForm init"); 
    } 
}); 

El código va a subir a

console.log("onSubmitLogin"); 

Y luego se detiene.

En el lanzamiento utilizo este:

var LoginForm = Ext.create("MyApp.view.LoginForm"); 
Ext.Viewport.add(LoginForm); 

Entonces, ¿cómo puedo obtener los valores?

Gracias

Respuesta

17

Ok. Encontré la respuesta después de algunos ajustes. Por el bien de las generaciones futuras, aquí está la solución:

He agregado id:'loginform' al LoginForm y luego, en el controlador en la parte 'refs', he agregado loginForm: '#loginform'. Entonces podría utilizarlo como:

var values = this.getLoginForm().getValues(); 

Buena suerte a todos

+0

¡Gracias por publicar su solución para esto! Me ayudó mucho. –

0

Prueba este

controlador:

 

    Ext.define("mySIMS.controller.LoginForm", { 
     extend : "Ext.app.Controller", 
     config : { 
      refs : { 
       btnSubmitLogin : "#btnSubmitLogin", 
       LoginForm : '#loginform' 
      }, 
      control : { 
       btnSubmitLogin : { 
        tap : "onSubmitLogin" 
       } 
      } 
     }, 
     onSubmitLogin : function() { 
      console.log("onSubmitLogin"); 
      var values = this.getLoginForm().getValues(); 
      console.log(values); 

      //var values = Oreilly.views.LoginForm.loginform.getValues(); 

     }, 
     launch : function() { 
      this.callParent(); 
      console.log("LoginForm launch"); 
     }, 
     init : function() { 
      this.callParent(); 
      console.log("LoginForm init"); 
     } 
    }); 

Vista:

 

    Ext.define('mySIMS.view.LoginForm', { 
     extend : 'Ext.form.Panel', 
     config : { 
      id : 'loginform', 
      fullscreen : true, 
      items : [{ 
       xtype : 'fieldset', 
       title : 'Login', 
       items : [{ 
        xtype : 'emailfield', 
        name : 'email', 
        label : 'Email' 
       }, { 
        xtype : 'passwordfield', 
        name : 'password', 
        label : 'Password' 
       }] 
      }, { 
       xtype : 'button', 
       width : '8%', 
       text : 'Login', 
       ui : 'confirm', 
       id : 'btnSubmitLogin' 
      }, { 
       xtype : 'toolbar', 
       docked : 'top', 
       title : 'Mobile' 
      }] 
     } 
    }); 

Esperanza esta ayuda.

+0

Sea más descriptivo sobre su solución. Consulte: [Cómo responder] (http://stackoverflow.com/questions/how-to-answer) – askmish

Cuestiones relacionadas