PDA

View Full Version : Submit a form



pegaso52it
22 Sep 2009, 6:40 AM
Hi all,
I have a form within one Ext.form.TextField configured within the property "allowBlank" to false, so is mandatory to enter a value.

The code used for submit the form is very simple:



myForm.submit(
{
url : something...l,
success : handleSubmittedForm,
failure : handleSubmittedFormFailure
});


If I submit the form within a value in mandatory textfield all goes well,
and "handleSubmittedForm" function is called.

If I submit the form with no value in mandatory textfield:
1) the handleSubmittedFormFailure is not called
2) Ext displays a message box within the message "Form fields may not be submitted with invalid values"

So my question is:
a) Why my function "handleSubmittedFormFailure" is not called?
Is there a way to force Ext to call it?
OR
b) Is there a way to NOT display the standard Ext error within a message box and
force Ext to call a my error handler function?

Thanks

22 Sep 2009, 6:47 AM
Step through your code. Look at what's returning back from the server. it requires at least {success:false} for the 'failure' action to be called.

pegaso52it
22 Sep 2009, 7:06 AM
Hi, Garcia
Thanks for your answer.
Probably I have explain my problem not so well.

If a mandatory TextField (allowblank = false) is empty Ext does not submit the form to the server.

Ext check first (on client side) is all form's fields are valid and if not (this is my case)
display the message "Form fields may not be submitted with invalid values"

But I do not want this message; is there a way to handle this client side error on my own?

22 Sep 2009, 7:10 AM
set allowBlank to true or don't set it at all

dtex-lab
22 Sep 2009, 7:35 AM
Hi, to solve your problem simply set the property "clientValidation" to true.

I mean:



myForm.submit({
clientValidation: true,
url: something,
success: handleSubmittedForm,
failure: handleSubmittedFormFailure
});



This makes ExtJS to call your "handleSubmittedFormFailure" function.

Why that?
Because clientValidation property has no default set, so is "undefined"

If u take a look in ExtJS Code:



run: function () {
var o = this.options;
var method = this.getMethod();
var isGet = method == 'GET';
if (o.clientValidation === false || this.form.isValid()) {
Ext.Ajax.request(Ext.apply(this.createCallback(o), {
form: this.form.el.dom,
url: this.getUrl(isGet),
method: method,
headers: o.headers,
params: !isGet ? this.getParams() : null,
isUpload: this.form.fileUpload
}));
} else if (o.clientValidation !== false) { // client validation failed
this.failureType = Ext.form.Action.CLIENT_INVALID;
this.form.afterAction(this, false);
}
},


It's easy to see that that property at least needs a value, so u have to set it always
on false or true.... but it starts as "undefined"

In my opinion might be better for ExtJS that some boolean properties (like that) must always has a default value when Ext's code requires it.
Or, minimum, Ext might document such properties as "required" in its documentation.

pegaso52it
22 Sep 2009, 7:51 AM
Thanks dtex-lab, you have solved my problem.