jquery - Is there a good way to deal with unobtrusive validation's seemingly asynchronous behavior? -
I have a short verification code run when I submit a form. Contradictory recognition has been established for my form.
("{strict} use"; $ ("# feedbackForm"). Submit (function () {var t = $ (This) .serialize (); var val = $ (this) .validate (); console.log (val.errorList.length); return false;});}) (); When I hit a breakpoint in Chrome, I see the following behavior:
You can see from the console that when the code was originally executed, it recognized 0 errors in the error list of verification, but when I got a breakpoint If I stop execution through, it recognizes 4 errors of verification error list is also with After the first time, is calculated correctly at the right number of runtime errors.
- How is this possible?
- How can I get the exact number of errors runtime?
Edit 1:
I can not reproduce this problem on jsfiddle, so something else should be run.
Edit 2:
I should also keep in mind that the setTimeout () within the submitler Using the correct result is the second time every time, but it only confirms what matitcom has mentioned in its answer.
Instead validate you have synchronous invalid handler You can use the check, in this way you know that it is complete. Perhaps it works in your bed probably is a coincidence because it is fast to validate the form, but your actual implementation is slow.
Submit this way:
$ ("# feedbackForm"). (Function () {var t = $ (this) .serialize (); $ (this) .validate ({invalidHandler: function (event, vedicator) {var errors = validator.numberOfInvalids (); if (errors) {if ( Validator.errorList.length & gt; {} (for x = 0; x & lt; validator.errorList.length; x ++) {console .log ("\ n \ u25CF" + validator.Terrorist [x] Message);}}}}}); $ (this). Validate (); returned;});
Comments
Post a Comment