PDA

View Full Version : override form fields on submit



dolittle
23 Feb 2010, 10:23 AM
Hi,

Is it possible to override values of form fields when submitting a FormPanel?
I don't want to change the actual field value because the user might need it if the submit fails.

I tried using

myFormPanel.getForm.submit({
params: {
field: 'val'
}
})

but I don't see it in firebug.

Thanks

tobiu
23 Feb 2010, 10:54 AM
hi dolittle,

one way would be to override the Ext.form.Action.Submit.
i found this in the forums and am experimenting with this to submit values of different formatted dateFields (multi-language...) in the same way.

you can find and replace special field-values by name or type with this too.


kind regards,
tobiu



bT.SubmitAction = function(form, options){
bT.SubmitAction.superclass.constructor.call(this, form, options);
};

Ext.extend(bT.SubmitAction, Ext.form.Action.Submit, {
run : function(){
if (!this.options.params) this.options.params = {};

this.form.items.each(function(field) {
if (field.disabled) {
this.options.params[field.getName()] = null;

} else if (field instanceof Ext.form.Checkbox) {
this.options.params[field.getName()] = field.getValue() ? 1 : 0;

} else if (field instanceof Ext.form.DateField) {
this.options.params[field.getName()] = field.getValue().dateFormat("Y-m-d");

} else if (field.rendered && field.el.dom.type == 'file') {
//skip, can't be read out through JS
return;
} /*else {
var v = field.getValue();
if (typeof v == 'object') {
v = Ext.encode(v);
}
this.options.params[field.getName()] = v;
}*/
if (field.rendered) {
field.realName = field.getName();
field.el.dom.name = '';
}
}, this);

bT.SubmitAction.superclass.run.call(this);

//restore names
this.form.items.each(function(field) {
if (field.realName) {
field.el.dom.name = field.realName;
delete field.realName;
}
}, this);
}
});
Ext.form.Action.ACTION_TYPES.submit = bT.SubmitAction;