Reputation: 5941
i am working on an application using sencha where i have a login screen with two buttons exit and submit. Here i am struggling for handling the events. Also i have two handlers for two buttons. But how can i get the text from the text fields ? how can i initiate a server request. Any help is highly appreciated.
Ext.setup({
icon: 'icon.png',
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
glossOnIcon: false,
onReady: function() {
var form;
var formBase = {
scroll : 'vertical',
standardSubmit : false,
items: [
{
xtype: 'fieldset',
title: 'Login Screen',
instructions: 'Enter agent number and password to login.',
defaults: {
required: true,
labelAlign: 'left',
labelWidth: '45%'
},
items: [
{
xtype: 'textfield',
name : 'username',
label: 'Agent Number',
useClearIcon: true
}, {
xtype: 'passwordfield',
name : 'password',
label: 'Password',
useClearIcon: false
}]
}],
listeners : {
submit : function(form, result){
console.log('success', Ext.toArray(arguments));
},
exception : function(form, result){
console.log('failure', result);
}
},
dockedItems: [
{
xtype: 'toolbar',
dock: 'bottom',
items: [
{
text: 'Login',
ui: 'confirm',
handler: function() {
alert('Login please wait..');
}
},
{
text: 'Exit',
ui: 'exit',
handler: function() {
alert('Are you sure ?');
}
}
]
}
]
};
if (Ext.is.Phone) {
formBase.fullscreen = true;
} else {
Ext.apply(formBase, {
autoRender: true,
floating: true,
modal: true,
centered: true,
hideOnMaskTap: false,
height: 385,
width: 480
});
}
form = new Ext.form.FormPanel(formBase);
form.show();
}
});
Upvotes: 0
Views: 389
Reputation: 2974
To get the values from the textfield use form.getValues();
. To make a request use:
Ext.Ajax.request({
url: 'ajax_demo/sample.json',
method: 'GET',
params:{
username:usernameValue,
password:passValue},
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);
}});
Update
First change the name of the fields to user
and pass
then put the following code instead alert('Login please wait..');
Ext.Ajax.request({
url: '140.45.45.20:9010/TService/Sms/Services',
params: form.getValues(),
method: 'GET',
success: function(response, opts) {
var obj = Ext.decode(response.responseText);
console.dir(obj);
//The request was successful - see the response in the response object
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
}});
Upvotes: 1