PDA

View Full Version : How Do I Make Params Dynamic and Connect Them to My Text Field.



robzdoom
22 Aug 2017, 12:14 PM
Background: I am attempting to make and API request with authentication. Now as of now I able able to make the Click on the field, and since I have hardcoded an email and password it works fine. But If I wanted to change that say there are going to be more than one user with different email and password, how do I go about approaching this issue? I essentially want to connect my text field boxes with the params in my Ajax request.

Thanks so much for help.

Regards, Jorge

This is my Ajax request


Ext.define('mockApp.controller.ajaxCall', {
extend: 'Ext.app.Controller',


control: {
"button#logInButton": {
tap: 'onButtonTap'
}
},


onButtonTap: function(button, e, eOpts) {
Ext.Ajax.request({
url: 'working url',
method: 'POST',
dataType: "json",
params: {
'UserEmail' : 'email',
'Password' : 'password',
},
success: function(response, opts) {
var obj = Ext.decode(response.responseText);
console.dir(obj);
},


failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
}
});


}


});


This is my Sign In page

xtype: 'panel', height: '',
bodyPadding: '10 10 20 20',
title: 'Sign In',
items: [
{
xtype: 'fieldset',
height: 186,
title: 'Please Enter Your Email and Password',
items: [
{
xtype: 'emailfield',
label: 'Email'
},
{
xtype: 'passwordfield',
label: 'Password'
},
{
xtype: 'toolbar',
docked: 'bottom',
layout: {
type: 'hbox',
pack: 'center'
},
items: [
{
xtype: 'button',
itemId: 'logInButton',
ui: 'confirm',
text: 'Log In'
},
{
xtype: 'button',
ui: 'decline',
text: 'Cancel'
}
]
}
]
}
]

petr.vecera
22 Aug 2017, 2:41 PM
There is many ways how to get the values, I have created fiddle with the very "basic" approach
https://fiddle.sencha.com/#view/editor&fiddle/25hp

There are better ways to do it. If you put everything in the form you should be able to get the form and simply get the values of the form.

Check out the examples here http://examples.sencha.com/extjs/6.5.1/examples/kitchensink/?modern#forms


Also it might be worth getting trough some example tutorials http://docs.sencha.com/architect/4/guides/tutorials/first_mobile_application.html

Definitely search trough the kithcensink and the docs pages there are several useful examples

Regards
Petr

robzdoom
23 Aug 2017, 8:55 AM
Ok I wanted to learn how to accomplish this using reference, How do I get this done when my controller is not in the same scope as the panel. My code is being executed in the code of the controller and not in the panel, so I wont be able to use the [this] code.What should my approach be when working on this code?

Thanks for the help yesterday,

Regards
Jorge

petr.vecera
23 Aug 2017, 11:24 AM
In the ViewController if you use this.getView() than you should be in scope of the View. So if you add some function to the view. In the view you should execute it using this.myFunction() , in the ViewController you should be able to do this.getView().myFunction()

robzdoom
23 Aug 2017, 11:51 AM
Thanks so much for your help. I really appreciate it.

Regards

Jorge