diff --git a/packages/react-form-renderer/src/get-condition-triggers/get-condition-triggers.js b/packages/react-form-renderer/src/get-condition-triggers/get-condition-triggers.js index 93b71b553..6875b3c7f 100644 --- a/packages/react-form-renderer/src/get-condition-triggers/get-condition-triggers.js +++ b/packages/react-form-renderer/src/get-condition-triggers/get-condition-triggers.js @@ -13,7 +13,7 @@ const mergeFunctionTrigger = (fn, field) => { const getConditionTriggers = (condition, field, conditionMapper = {}) => { let triggers = []; if (Array.isArray(condition)) { - return condition.reduce((acc, item) => [...acc, ...getConditionTriggers(item, field)], []); + return condition.reduce((acc, item) => [...acc, ...getConditionTriggers(item, field, conditionMapper)], []); } // extract mapped attributes to a new static condition object @@ -58,13 +58,13 @@ const getConditionTriggers = (condition, field, conditionMapper = {}) => { nestedKeys.forEach((key) => { if (typeof rest[key] !== 'undefined') { rest[key].forEach((item) => { - triggers = [...triggers, ...getConditionTriggers(item, field)]; + triggers = [...triggers, ...getConditionTriggers(item, field, conditionMapper)]; }); } }); if (typeof condition.not === 'object') { - triggers = [...triggers, ...getConditionTriggers(condition.not, field)]; + triggers = [...triggers, ...getConditionTriggers(condition.not, field, conditionMapper)]; } return Array.from(new Set(triggers)); diff --git a/packages/react-form-renderer/src/get-visible-fields/get-visible-fields.js b/packages/react-form-renderer/src/get-visible-fields/get-visible-fields.js index 14bcb9a36..941d18082 100644 --- a/packages/react-form-renderer/src/get-visible-fields/get-visible-fields.js +++ b/packages/react-form-renderer/src/get-visible-fields/get-visible-fields.js @@ -1,17 +1,17 @@ import parseCondition from '../parse-condition'; -const getVisibleFields = (schema, values) => { +const getVisibleFields = (schema, values, conditionMapper) => { if (Array.isArray(schema)) { - return schema.map((field) => getVisibleFields(field, values)).filter(Boolean); + return schema.map((field) => getVisibleFields(field, values, undefined, conditionMapper)).filter(Boolean); } if (schema.condition) { - const result = parseCondition(schema.condition, values, schema); + const result = parseCondition(schema.condition, values, schema, conditionMapper); if (result.visible) { return { ...schema, - ...(schema.fields && { fields: getVisibleFields(schema.fields, values).filter(Boolean) }), + ...(schema.fields && { fields: getVisibleFields(schema.fields, values, undefined, conditionMapper).filter(Boolean) }), }; } else { return null; @@ -20,7 +20,7 @@ const getVisibleFields = (schema, values) => { return { ...schema, - ...(schema.fields && { fields: getVisibleFields(schema.fields, values).filter(Boolean) }), + ...(schema.fields && { fields: getVisibleFields(schema.fields, values, undefined, conditionMapper).filter(Boolean) }), }; }; diff --git a/packages/react-form-renderer/src/parse-condition/parse-condition.js b/packages/react-form-renderer/src/parse-condition/parse-condition.js index 93cdd2bc5..15cbc2964 100644 --- a/packages/react-form-renderer/src/parse-condition/parse-condition.js +++ b/packages/react-form-renderer/src/parse-condition/parse-condition.js @@ -89,7 +89,7 @@ export const parseCondition = (condition, values, field, conditionMapper = {}) = }; if (Array.isArray(condition)) { - return !condition.map((condition) => parseCondition(condition, values, field)).some(({ result }) => result === false) + return !condition.map((condition) => parseCondition(condition, values, field, conditionMapper)).some(({ result }) => result === false) ? positiveResult : negativeResult; } @@ -97,7 +97,7 @@ export const parseCondition = (condition, values, field, conditionMapper = {}) = const conditionInternal = unpackMappedCondition(condition, conditionMapper); if (conditionInternal.and) { - return !conditionInternal.and.map((condition) => parseCondition(condition, values, field)).some(({ result }) => result === false) + return !conditionInternal.and.map((condition) => parseCondition(condition, values, field, conditionMapper)).some(({ result }) => result === false) ? positiveResult : negativeResult; } @@ -105,7 +105,7 @@ export const parseCondition = (condition, values, field, conditionMapper = {}) = if (conditionInternal.sequence) { return conditionInternal.sequence.reduce( (acc, curr) => { - const result = parseCondition(curr, values, field); + const result = parseCondition(curr, values, field, conditionMapper); return { sets: [...acc.sets, ...(result.set ? [result.set] : [])], @@ -118,13 +118,13 @@ export const parseCondition = (condition, values, field, conditionMapper = {}) = } if (conditionInternal.or) { - return conditionInternal.or.map((condition) => parseCondition(condition, values, field)).some(({ result }) => result === true) + return conditionInternal.or.map((condition) => parseCondition(condition, values, field, conditionMapper)).some(({ result }) => result === true) ? positiveResult : negativeResult; } if (conditionInternal.not) { - return !parseCondition(conditionInternal.not, values, field).result ? positiveResult : negativeResult; + return !parseCondition(conditionInternal.not, values, field, conditionMapper).result ? positiveResult : negativeResult; } const finalWhen = typeof conditionInternal.when === 'function' ? conditionInternal.when(field) : conditionInternal.when; diff --git a/packages/react-form-renderer/src/validation/validation.js b/packages/react-form-renderer/src/validation/validation.js index 5ae0d2382..3245d4a53 100644 --- a/packages/react-form-renderer/src/validation/validation.js +++ b/packages/react-form-renderer/src/validation/validation.js @@ -32,7 +32,7 @@ const validation = async (schema, options) => { throw new Error(`options argument has to be type of object, provided: ${typeof options}`); } - const { values, componentMapper, validatorMapper, actionMapper, schemaValidatorMapper, omitWarnings } = options; + const { values, componentMapper, validatorMapper, actionMapper, schemaValidatorMapper, omitWarnings, conditionMapper } = options; const validatorMapperMerged = { ...defaultValidatorMapper, ...validatorMapper }; @@ -49,7 +49,7 @@ const validation = async (schema, options) => { defaultSchemaValidator(finalSchema, finalComponentMapper, validatorTypes, actionTypes, schemaValidatorMapper); - finalSchema = getVisibleFields(finalSchema, values); + finalSchema = getVisibleFields(finalSchema, values, undefined, conditionMapper); const validates = getValidates(finalSchema, { componentMapper: finalComponentMapper, actionMapper, values });