Skip to content

Commit

Permalink
fix: Return sub rule if the error is related to a sub rule (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
relekang committed May 19, 2016
1 parent f012d97 commit 5051215
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class Validator {
result = this.validateRule(rule, field, value, this.config[field][rule]);

if (result) {
result = { field, rule, value };
result = { field, rule: result, value };
this.errors = assign({}, this.errors, { [field]: result });
break;
} else {
Expand Down
9 changes: 9 additions & 0 deletions test/validator_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ test('validateField should update errors', t => {
validator.validateField('a', 'c');
t.deepEqual(validator.errors, {});
});

test('validateField should return object with offending rule name', t => {
const validator = new Validator({ a: { numeric: { integerOnly: true } } });

t.deepEqual(
validator.validateField('a', '2.0'),
{ field: 'a', rule: 'numeric/integerOnly', value: '2.0' }
);
});

0 comments on commit 5051215

Please sign in to comment.