From 75cda2bf29f6bd303a226e0e3406a0d12beb82f6 Mon Sep 17 00:00:00 2001 From: Chunpeng Huo Date: Mon, 4 Nov 2019 14:20:30 +1100 Subject: [PATCH] fix: allow if transformer to access custom options closes #3 --- src/standard-validators.js | 3 ++- src/validation.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/standard-validators.js b/src/standard-validators.js index a3435a8..7cd920e 100644 --- a/src/standard-validators.js +++ b/src/standard-validators.js @@ -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)) { diff --git a/src/validation.js b/src/validation.js index 3e473f9..6aee758 100644 --- a/src/validation.js +++ b/src/validation.js @@ -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; }