If you have several fields that fail during prevalidation, the subsequent ones will still get a prompt. This is with stock standard required checks without any groups.
This is due to parallelize rejecting as soon as one task fails. The other tasks aren't aborted, and so continue after showPrompt has been turned back on.
If you wanted a boolean result derived from AND logic, I'd expect to just abort the other tasks. But for a prevalidate determining the status of all fields it doesn't seem right to do that.
As such I made the fail logic pretty much the same as the success logic and this fixes the problem. Not thoroughly tested but my final code was:
diff --git a/vendor/assets/javascripts/jquery.async.validator.prompt.js b/vendor/assets/javascripts/jquery.async.validator.prompt.js
index f79c14b..7574627 100644
--- a/vendor/assets/javascripts/jquery.async.validator.prompt.js
+++ b/vendor/assets/javascripts/jquery.async.validator.prompt.js
@@ -452,20 +452,26 @@ $.Deferred.parallelize = function(fns) {
var d = $.Deferred(),
n = 0, i = 0, l = fns.length,
- rejected = false;
+ rejection = null;
if(!$.isArray(fns) || l === 0)
return d.resolve();
function pass(result) {
- n++;
- if(n === l) d.resolve(result);
+ maybe_resolve();
}
function fail(result) {
- if(rejected) return;
- rejected = true;
- d.reject(result);
+ if (rejection == null) rejection = result;
+ maybe_resolve();
+ }
+
+ function maybe_resolve() {
+ n++;
+ if(n === l) {
+ if (rejection == null) d.resolve();
+ else d.reject(rejection);
+ }
}
//execute all at once
If you have several fields that fail during prevalidation, the subsequent ones will still get a prompt. This is with stock standard required checks without any groups.
Excerpt:
This is due to parallelize rejecting as soon as one task fails. The other tasks aren't aborted, and so continue after showPrompt has been turned back on.
Note this code:
If you wanted a boolean result derived from AND logic, I'd expect to just abort the other tasks. But for a prevalidate determining the status of all fields it doesn't seem right to do that.
As such I made the fail logic pretty much the same as the success logic and this fixes the problem. Not thoroughly tested but my final code was: