Skip to content

Commit

Permalink
fix: allow if transformer to access custom options
Browse files Browse the repository at this point in the history
closes #3
  • Loading branch information
3cp committed Nov 4, 2019
1 parent db160f4 commit 75cda2b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/standard-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ export const ifTester = function (rule) {
export const ifTransformer = function (rule) {
const _if = _.get(rule, 'if');
const subRule = _.omit(rule, 'if');
const options = _.omit(subRule, 'group', 'validate', 'value', 'message');

let rules = [];
// if condition is false, skip the real validation
rules.push({validate: "skipImmediatelyIf", value: `!(${_if})`});
rules.push({validate: "skipImmediatelyIf", value: `!(${_if})`, ...options});

if (_.has(subRule, 'group') &&
_.isArray(subRule.group)) {
Expand Down
2 changes: 1 addition & 1 deletion src/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Validation {
// support binding on option like "maxLength.bind":...
const trueName = name.substr(0, name.length - 5);
const optionEval = valueEvaluator(v);
variation[`$${trueName}`] = optionEval && optionEval(scope) || v;
variation[`$${trueName}`] = optionEval(scope);
} else {
variation[`$${name}`] = v;
}
Expand Down

0 comments on commit 75cda2b

Please sign in to comment.