From 980a0fafea8fbe6bbb462d428b9162eabfe1fd25 Mon Sep 17 00:00:00 2001 From: Simon Haga <1498414+sewil@users.noreply.github.com> Date: Wed, 16 Oct 2019 10:02:46 +0200 Subject: [PATCH 1/6] attribute label --- validate.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/validate.js b/validate.js index adf023b..b2d0a5b 100644 --- a/validate.js +++ b/validate.js @@ -102,6 +102,9 @@ validators = v.result(constraints[attr], value, attributes, attr, options, constraints); for (validatorName in validators) { + if (validatorName === 'attributeLabel') ( + continue; + ) validator = v.validators[validatorName]; if (!validator) { @@ -121,6 +124,7 @@ } results.push({ attribute: attr, + attributeLabel: validators.attributeLabel, value: value, validator: validatorName, globalOptions: options, @@ -649,7 +653,7 @@ if (error[0] === '^') { error = error.slice(1); } else if (options.fullMessages !== false) { - error = v.capitalize(prettify(errorInfo.attribute)) + " " + error; + error = v.capitalize(prettify(errorInfo.attributeLabel || errorInfo.attribute)) + " " + error; } error = error.replace(/\\\^/g, "^"); error = v.format(error, { From dc1d1154a5cd47f518200bdd987aad4d84f623a0 Mon Sep 17 00:00:00 2001 From: Simon Haga <1498414+sewil@users.noreply.github.com> Date: Wed, 16 Oct 2019 10:06:47 +0200 Subject: [PATCH 2/6] Update validate.js --- validate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validate.js b/validate.js index b2d0a5b..cb173f0 100644 --- a/validate.js +++ b/validate.js @@ -102,9 +102,9 @@ validators = v.result(constraints[attr], value, attributes, attr, options, constraints); for (validatorName in validators) { - if (validatorName === 'attributeLabel') ( + if (validatorName === 'attributeLabel') { continue; - ) + } validator = v.validators[validatorName]; if (!validator) { From 7fb6482ed425fe1edf6a31ddb2e0631f54ff5840 Mon Sep 17 00:00:00 2001 From: Simon Haga <1498414+sewil@users.noreply.github.com> Date: Wed, 16 Oct 2019 10:38:04 +0200 Subject: [PATCH 3/6] Update validate.js --- validate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validate.js b/validate.js index cb173f0..42240a5 100644 --- a/validate.js +++ b/validate.js @@ -653,7 +653,7 @@ if (error[0] === '^') { error = error.slice(1); } else if (options.fullMessages !== false) { - error = v.capitalize(prettify(errorInfo.attributeLabel || errorInfo.attribute)) + " " + error; + error = errorInfo.attributeLabel || v.capitalize(prettify(errorInfo.attribute)) + " " + error; } error = error.replace(/\\\^/g, "^"); error = v.format(error, { From 579f9c94929ceb007e6ae2212406e33baf300c9d Mon Sep 17 00:00:00 2001 From: Simon Haga <1498414+sewil@users.noreply.github.com> Date: Wed, 16 Oct 2019 10:40:33 +0200 Subject: [PATCH 4/6] Update validate.js --- validate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validate.js b/validate.js index 42240a5..64533f7 100644 --- a/validate.js +++ b/validate.js @@ -653,7 +653,7 @@ if (error[0] === '^') { error = error.slice(1); } else if (options.fullMessages !== false) { - error = errorInfo.attributeLabel || v.capitalize(prettify(errorInfo.attribute)) + " " + error; + error = (errorInfo.attributeLabel || v.capitalize(prettify(errorInfo.attribute))) + " " + error; } error = error.replace(/\\\^/g, "^"); error = v.format(error, { From dcbdd58487d53e958937253b7bb7f26befc4eb3d Mon Sep 17 00:00:00 2001 From: Simon Haga <1498414+sewil@users.noreply.github.com> Date: Thu, 19 Dec 2019 15:49:09 +0100 Subject: [PATCH 5/6] Add attributeLabel to validate-spec and validate.html --- docs/validate.html | 6 +++++- specs/validate-spec.js | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/validate.html b/docs/validate.html index f61b7aa..872f142 100644 --- a/docs/validate.html +++ b/docs/validate.html @@ -234,6 +234,9 @@

validate.js

        validators = v.result(constraints[attr], value, attributes, attr, options, constraints);
 
         for (validatorName in validators) {
+          if (validatorName === 'attributeLabel') {
+            continue;
+          }
           validator = v.validators[validatorName];
 
           if (!validator) {
@@ -266,6 +269,7 @@ 

validate.js

} results.push({ attribute: attr, + attributeLabel: validators.attributeLabel, value: value, validator: validatorName, globalOptions: options, @@ -1240,7 +1244,7 @@

validate.js

if (error[0] === '^') { error = error.slice(1); } else if (options.fullMessages !== false) { - error = v.capitalize(prettify(errorInfo.attribute)) + " " + error; + error = (errorInfo.attributeLabel || v.capitalize(prettify(errorInfo.attribute))) + " " + error; } error = error.replace(/\\\^/g, "^"); error = v.format(error, { diff --git a/specs/validate-spec.js b/specs/validate-spec.js index f18f6fc..610a2dc 100644 --- a/specs/validate-spec.js +++ b/specs/validate-spec.js @@ -131,6 +131,7 @@ describe("validate", function() { expect(result).toHaveItems([{ attribute: "name", + attributeLabel: undefined, value: "test", validator: "fail", options: options, @@ -139,6 +140,7 @@ describe("validate", function() { error: "foobar" }, { attribute: "name", + attributeLabel: undefined, value: "test", validator: "fail2", options: true, @@ -147,6 +149,7 @@ describe("validate", function() { error: ["foo", "bar"] }, { attribute: "name", + attributeLabel: undefined, value: "test", validator: "pass", options: true, @@ -166,6 +169,7 @@ describe("validate", function() { expect(validate.runValidations({}, constraints, {})).toHaveItems([ { attribute: "attr1", + attributeLabel: undefined, value: undefined, validator: "pass", options: {foo: "bar"}, @@ -174,6 +178,7 @@ describe("validate", function() { error: undefined }, { attribute: "attr2", + attributeLabel: undefined, value: undefined, validator: "fail", options: true, @@ -182,6 +187,7 @@ describe("validate", function() { error: "error" }, { attribute: "attr3", + attributeLabel: undefined, value: undefined, validator: "fail", options: true, @@ -393,6 +399,7 @@ describe("validate", function() { var options = {format: "detailed"}; expect(validate(attributes, c, options)).toHaveItems([{ attribute: "foo", + attributeLabel: undefined, value: "foo", validator: "length", options: { @@ -405,6 +412,7 @@ describe("validate", function() { error: "foobar" }, { attribute: "bar", + attributeLabel: undefined, value: 10, validator: "numericality", options: { @@ -416,6 +424,7 @@ describe("validate", function() { error: "Bar must be greater than 15" }, { attribute: "bar", + attributeLabel: undefined, value: 10, validator: "numericality", options: { From bf246b6585397600644af5608838252df6052acc Mon Sep 17 00:00:00 2001 From: Simon Haga <1498414+sewil@users.noreply.github.com> Date: Thu, 19 Dec 2019 15:52:54 +0100 Subject: [PATCH 6/6] Increase code coverage --- specs/validate-spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/validate-spec.js b/specs/validate-spec.js index 610a2dc..6519245 100644 --- a/specs/validate-spec.js +++ b/specs/validate-spec.js @@ -164,7 +164,7 @@ describe("validate", function() { var constraints = { attr1: {pass: {foo: "bar"}}, attr2: {fail: true}, - attr3: {fail: true} + attr3: {fail: true, attributeLabel: "foobar"} }; expect(validate.runValidations({}, constraints, {})).toHaveItems([ { @@ -187,7 +187,7 @@ describe("validate", function() { error: "error" }, { attribute: "attr3", - attributeLabel: undefined, + attributeLabel: "foobar", value: undefined, validator: "fail", options: true,