I have a form in which there is a textArea. This form is validated first by Ajax to check if the texArea text is large enough and after this, it is validated in the controller action for the rest of the data.
Well, the first time I submit, the textArea text arrives empty and the validator that is done by ajax gives an error, but if I do it again I submit without touching anything, the text does arrive well and it Validate everything perfect.
Code in the form that calls the JS function
$this->getView()->JQReady('
$("form").submit(function(event) {
if (!js.Form.validate($(this), "item/validate")) {
event.preventDefault();
event.stopImmediatePropagation();
}
});
');
JS code
validate: function(form, urlValidate) {
var datastring = form.serialize();
var returnValue = false;
$.ajax({
async: false,
type: "POST",
url: urlValidate,
data: datastring,
dataType: "json",
success: function(data) {
var request = JSON.parse(data);
if (!request.valid) {
if (request.exception) {
if (request.exception) {
form.unbind("submit").submit();
}
returnValue = true;
} else {
printFormErrors(form, request.errors);
restoreSubmitButtonItem();
}
} else {
returnValue = true;
}
},
error: function(data) {
form.unbind("submit").submit();
returnValue = true;
restoreSubmitButtonItem();
}
});
return returnValue;
}
Only one isValid is done in the controller. Any ideas?