PDA

View Full Version : TIP / Example: submitting form on enter.



dimentox
11 Jan 2011, 12:02 PM
I may be doing this wrong but heres how i solved the enter submit.



var form = new Ext.FormPanel({
labelAlign: 'left',
//applyTo: 'hello-tabs',
layout: 'form',
padding: 10,
items: [
{
xtype: 'textfield',
fieldLabel: 'User Name',
labelStyle: 'font-weight:bold;',
name: 'UserName',
id: 'user',
allowBlank: false
},
{
xtype: 'textfield',
inputType: 'password',
fieldLabel: 'Password',
labelStyle: 'font-weight:bold;',
id: 'Password',
allowBlank: false,
name: 'Password'
},
{
xtype: 'checkbox',
fieldLabel: 'Remember Me',
name: 'RememberMe'
}
],
keys: [
{ key: [Ext.EventObject.ENTER], handler: function (a, b, c)
{
var element = form.loginbutton;
// var e = new Ext.EventObject();
b.button = 0;
element.onClick(b);
}
}
],
buttons: [{
text: 'Login',
ref: '../loginbutton',
id: 'loginbutton',
formBind: true,
handler: function ()
{
var busy = Ext.Msg.wait("Please Wait", "Please Wait", null);
form.getForm().submit({
clientValidation: true,
url: '/Account/LogOn',

success: function (form, action)
{
busy.hide();
window.location.reload();
},
failure: function (form, action)
{
busy.hide();
switch (action.failureType)
{
case Ext.form.Action.CLIENT_INVALID:
Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
break;
case Ext.form.Action.CONNECT_FAILURE:
Ext.Msg.alert('Failure', 'Ajax communication failed');
break;
case Ext.form.Action.SERVER_INVALID:
Ext.Msg.alert('Failure', action.result.msg);
}
}
});
}
}]
});