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..6519245 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, @@ -161,11 +164,12 @@ 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([ { 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: "foobar", 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: { diff --git a/validate.js b/validate.js index adf023b..64533f7 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 = (errorInfo.attributeLabel || v.capitalize(prettify(errorInfo.attribute))) + " " + error; } error = error.replace(/\\\^/g, "^"); error = v.format(error, {