[jQuery] [validate] validator.pendingRequest below 0
Hey Jorn,
I believe I have found a bug in jquery.validate 1.2.
I use a few "remote"s to make sure a username or an email is not
taken. Sometimes I would have some errors in my form and would click
the submit button a few times to validate fields - and then would fix
the fields containing errors, and then try to submit the form, but it
would simply not submit. So after a lot of trial and error I decided
to add the following line:
alert(validator.pendingRequest);
in this block of jquery.Validate code:
if ( validator.pendingRequest ) {
alert(validator.pendingRequest); //The line I added
validator.formSubmitted = true;
return false;
}
In one instance I got -3 as a result - meaning that requests
inexistent request were cancelled, lowering validator.pendingRequest
below zero.
Solution:
Replace the existing stopRequest function
stopRequest: function(element, valid) {
this.pendingRequest--;
delete this.pending[element.name];
if ( valid && this.pendingRequest == 0 && this.formSubmitted &&
this.form() ) {
jQuery(this.currentForm).submit();
}
},
With this one
stopRequest: function(element, valid) {
if(this.pendingRequest>0){ //NOTICE THIS
this.pendingRequest--;
} //NOTICE THIS
delete this.pending[element.name];
if ( valid && this.pendingRequest == 0 && this.formSubmitted &&
this.form() ) {
jQuery(this.currentForm).submit();
}
},
so pendingRequest is only lowered if it is greater than 0 - resulting
in the form actually being submitted when all fields are correct.
Hope I could help and things would be fixed in the next release.
Thanks,
Yuval Karmi