Sencha Touch 2 - How to get form values?
11,281
Ok. Found the answer after some tweaking. For the sake of future generations - here is the solution:
I've added id:'loginform'
to the LoginForm and then, in the controller in the 'refs' part I've added loginForm: '#loginform'
.
Then I could use it as :
var values = this.getLoginForm().getValues();
Good luck to all
Author by
Roman
Updated on June 05, 2022Comments
-
Roman almost 2 years
I've got a Sencha Touch 2 MVC app with a form as a view. I'm trying to get it's values from the controller with no success.
How could this be done? I'm posting my view/controller code for this one.
View:
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' } ] } });
And the controller:
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"); } });
The code will go up to
console.log("onSubmitLogin");
And then stop.
On launch I use this:
var LoginForm = Ext.create("MyApp.view.LoginForm"); Ext.Viewport.add(LoginForm);
So, how can I get the values?
Thanks
-
Matt McClure about 12 yearsThanks for posting your solution to this! It helped me out greatly.
-
askmish over 11 yearsPlease be more descriptive about your solution. Refer:How to Answer