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
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
Share Improve this question asked Mar 13, 2012 at 13:23 RomanRoman 4,51314 gold badges60 silver badges81 bronze badges2 Answers
Reset to default 16Ok. 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
Try this
Controller:
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"); } });
View:
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' }] } });
Hope this help.