Tuesday, December 29, 2009

Re: [jQuery] (validation): remote rule causes submit to abort, fix included

I ran into the same problem as Ken.

Calling $("#form").validate().form() would yield true, even when the remote
validation should have been failing. The problem is...

(1) When calling .validate.form() -- it returns prematurely with the status
of "pending" for all remote validation rules.

(2) After the call to .validate.form() -- the validating ajax call returns
with the proper status; however, at this point, it's too late. Even calling
.validate.form() twice will not work, as the code checks each value against
the previous value.

Ken's solution fixed my problem, but I would love to see it included in the
jquery validation package. I love this plugin and I appreciate all of the
hard work that went into it.

Many thanks,
Adam

KenGreer wrote:
>
> With the validation plugin (http://bassistance.de/jquery-plugins/
> jquery-plugin-validation/) I included two "remote" rules to check
> username and e-mail. If my form is loaded such that the username and e-
> mail are already filled in, and, therefore, have not yet been
> validated, and I click SUBMIT, validation proceeds just fine, but the
> form does NOT submit! A second click of the submit button, however,
> then works.
>
> I speculated that this was because of pending ajax calls aborting the
> submit. It seems my speculation held true. Right after my "$
> (document).ready(function() { ..." I added the code:
>
> $.ajaxSetup( {
> async: false
> } );
>
> to make the "remote" ajax calls synchronous and this fixed the
> problem. Now clicking submit performs the validation and really does
> submit.
>
> Hopefully a more elegant solution will be found in the validation
> plugin itself, but as a jquery newbie, I found reading the validation
> plugin code daunting!
>
>

--
View this message in context: http://old.nabble.com/%28validation%29%3A-remote-rule-causes-submit-to-abort%2C-fix--included-tp26874437s27240p26963755.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

No comments: