Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/validate.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ <h1>validate.js</h1>
<div class="content"><div class='highlight'><pre> validators = v.result(constraints[attr], value, attributes, attr, options, constraints);

<span class="hljs-keyword">for</span> (validatorName <span class="hljs-keyword">in</span> validators) {
<span class="hljs-keyword">if</span> (validatorName === <span class="hljs-string">'attributeLabel'</span>) {
<span class="hljs-keyword">continue</span>;
}
validator = v.validators[validatorName];

<span class="hljs-keyword">if</span> (!validator) {
Expand Down Expand Up @@ -266,6 +269,7 @@ <h1>validate.js</h1>
}
results.push({
<span class="hljs-attr">attribute</span>: attr,
<span class="hljs-attr">attributeLabel</span>: validators.attributeLabel,
<span class="hljs-attr">value</span>: value,
<span class="hljs-attr">validator</span>: validatorName,
<span class="hljs-attr">globalOptions</span>: options,
Expand Down Expand Up @@ -1240,7 +1244,7 @@ <h1>validate.js</h1>
<span class="hljs-keyword">if</span> (error[<span class="hljs-number">0</span>] === <span class="hljs-string">'^'</span>) {
error = error.slice(<span class="hljs-number">1</span>);
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (options.fullMessages !== <span class="hljs-literal">false</span>) {
error = v.capitalize(prettify(errorInfo.attribute)) + <span class="hljs-string">" "</span> + error;
error = (errorInfo.attributeLabel || v.capitalize(prettify(errorInfo.attribute))) + <span class="hljs-string">" "</span> + error;
}
error = error.replace(<span class="hljs-regexp">/\\\^/g</span>, <span class="hljs-string">"^"</span>);
error = v.format(error, {
Expand Down
11 changes: 10 additions & 1 deletion specs/validate-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ describe("validate", function() {

expect(result).toHaveItems([{
attribute: "name",
attributeLabel: undefined,
value: "test",
validator: "fail",
options: options,
Expand All @@ -139,6 +140,7 @@ describe("validate", function() {
error: "foobar"
}, {
attribute: "name",
attributeLabel: undefined,
value: "test",
validator: "fail2",
options: true,
Expand All @@ -147,6 +149,7 @@ describe("validate", function() {
error: ["foo", "bar"]
}, {
attribute: "name",
attributeLabel: undefined,
value: "test",
validator: "pass",
options: true,
Expand All @@ -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"},
Expand All @@ -174,6 +178,7 @@ describe("validate", function() {
error: undefined
}, {
attribute: "attr2",
attributeLabel: undefined,
value: undefined,
validator: "fail",
options: true,
Expand All @@ -182,6 +187,7 @@ describe("validate", function() {
error: "error"
}, {
attribute: "attr3",
attributeLabel: "foobar",
value: undefined,
validator: "fail",
options: true,
Expand Down Expand Up @@ -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: {
Expand All @@ -405,6 +412,7 @@ describe("validate", function() {
error: "foobar"
}, {
attribute: "bar",
attributeLabel: undefined,
value: 10,
validator: "numericality",
options: {
Expand All @@ -416,6 +424,7 @@ describe("validate", function() {
error: "Bar must be greater than 15"
}, {
attribute: "bar",
attributeLabel: undefined,
value: 10,
validator: "numericality",
options: {
Expand Down
6 changes: 5 additions & 1 deletion validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -121,6 +124,7 @@
}
results.push({
attribute: attr,
attributeLabel: validators.attributeLabel,
value: value,
validator: validatorName,
globalOptions: options,
Expand Down Expand Up @@ -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, {
Expand Down