PDA

View Full Version : Normal submission of an Ext Form (FormPanel)



Sierra
15 Jan 2008, 4:43 PM
For all those people looking for a way to submit a FormPanel the old fashioned way in ExtJS 2.0



Ext.onReady(function(){

Ext.QuickTips.init();

// turn on validation errors beside the field globally
Ext.form.Field.prototype.msgTarget = 'side';

var login_form = new Ext.FormPanel({

id: login_form,
labelWidth: 75,
frame:true,
title: 'enterwhateveryouwant',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {width: 230},
onSubmit: Ext.emptyFn,
submit: function() {
this.getForm().getEl().dom.action = 'enterthepageyouneed';
this.getForm().getEl().dom.submit();
},
defaultType: 'textfield',

items: [{
fieldLabel: 'Email',
name: 'email',
vtype:'email',
allowBlank:false
},{
fieldLabel: 'Password',
inputType:'password',
name: 'password',
allowBlank:false
},{

name: 'enterwhateveryouwant',
inputType:'hidden',
value: 'enterwhateveryouwant'

}
],buttons: [{
text: 'Login',
handler: submitForm
}]
});


function submitForm(){
login_form.submit();
}

login_form.render('login_form');

});


thanks to jg4smile (http://extjs.com/forum/member.php?u=2340)who posted the "important parts" of this first ;)

SplitDestiny
16 Jan 2008, 12:36 PM
Thanks for this. I've been racking my brain over trying to figure out how to get a simple post request to work so I can integrate code I already have.

boxorox
19 Jan 2008, 12:20 PM
Thanks for this. I've been racking my brain over trying to figure out how to get a simple post request to work so I can integrate code I already have.


+1-bazillion!!!


I'm new to this and finally starting to wrap my brain around Ext! But i couldn't for the life of me figure out why setting the url property of the FormPanel wasn't translating to an action for my form. But this did the trick! thank you thank you thank you! :D

On thing I did was use the url property on FormPanel for my action. Makes it at a little more consistent with the default form handling.




submit: function() {
this.getForm().getEl().dom.action = this.url;
this.getForm().getEl().dom.submit();
}
So the final question is... would it be possible to update the FormPanel documentation to include a note about setting the this.getForm().getEl().dom.action where it talks about enabling "normal browser submission"?

Thanks!