From 2602c25fafcdb7c4e6b9c6c3594e0765337c19e1 Mon Sep 17 00:00:00 2001 From: Harry Lascelles Date: Wed, 2 Oct 2013 12:19:45 +0100 Subject: [PATCH 1/2] Add the ability to see which rule object has errored --- Src/knockout.validation.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Src/knockout.validation.js b/Src/knockout.validation.js index 6e488b0a..040f1519 100644 --- a/Src/knockout.validation.js +++ b/Src/knockout.validation.js @@ -950,6 +950,9 @@ return observable.__valid__(); }); + // Holds which rule is in error + observable.errorRule = ko.observable(null); + //manually set error state observable.setError = function (error) { observable.error(error); @@ -1000,6 +1003,7 @@ //not valid, so format the error message and stick it in the 'error' variable observable.error(exports.formatMessage(ctx.message || rule.message, ctx.params)); observable.__valid__(false); + observable.errorRule(rule); return false; } else { return true; @@ -1070,6 +1074,7 @@ } else { //run normal sync validation if (!validateSync(observable, rule, ctx)) { + observable.errorRule(null); // Clear the errored rule return false; //break out of the loop } } From 281528693474186cc8e8071fcc8ce2ee28f8c2e9 Mon Sep 17 00:00:00 2001 From: Harry Lascelles Date: Wed, 2 Oct 2013 12:58:19 +0100 Subject: [PATCH 2/2] Moving reset --- Src/knockout.validation.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Src/knockout.validation.js b/Src/knockout.validation.js index 040f1519..8bf4accf 100644 --- a/Src/knockout.validation.js +++ b/Src/knockout.validation.js @@ -1074,12 +1074,14 @@ } else { //run normal sync validation if (!validateSync(observable, rule, ctx)) { - observable.errorRule(null); // Clear the errored rule return false; //break out of the loop } } } //finally if we got this far, make the observable valid again! + if (observable.errorRule) { + observable.errorRule(null); // Clear the errored rule + } observable.error(null); observable.__valid__(true); return true;