diff --git a/src/process/__tests__/process.test.ts b/src/process/__tests__/process.test.ts index dc286f68..b2831a24 100644 --- a/src/process/__tests__/process.test.ts +++ b/src/process/__tests__/process.test.ts @@ -3133,7 +3133,7 @@ describe('Process Tests', () => { processSync(context); expect(context.data).to.deep.equal({ - candidates:[{candidate:{data:{section6:{}}}}], + candidates:[{candidate:{data:{section6:{ "c":{}, "d":[]}}}}], submit: true }); }); @@ -3183,7 +3183,7 @@ describe('Process Tests', () => { processSync(context); expect(context.data).to.deep.equal({ - candidates:[{candidate:{data:{section6:{}}}}], + candidates:[{candidate:{data:{}}}], submit: true }); }); diff --git a/src/process/clearHidden.ts b/src/process/clearHidden.ts index 03ed8e80..18ea3880 100644 --- a/src/process/clearHidden.ts +++ b/src/process/clearHidden.ts @@ -36,7 +36,7 @@ export const clearHiddenProcess: ProcessorFnSync = (context) = const shouldClearValueWhenHidden = !component.hasOwnProperty('clearOnHide') || component.clearOnHide; - if (shouldClearValueWhenHidden && (isConditionallyHidden || isParentHidden(component))) { + if (shouldClearValueWhenHidden && (isConditionallyHidden || isParentHidden(component) || component.hidden)) { unset(data, path); scope.clearHidden[path] = true; } diff --git a/src/process/conditions/__tests__/conditions.test.ts b/src/process/conditions/__tests__/conditions.test.ts index 9b7441a5..05467f37 100644 --- a/src/process/conditions/__tests__/conditions.test.ts +++ b/src/process/conditions/__tests__/conditions.test.ts @@ -53,8 +53,9 @@ describe('Condition processor', () => { form, submission ); - expect(context.components[1]).to.haveOwnProperty('hidden'); - expect(context.components[1].hidden).to.be.true; + expect(context.scope.conditionals).to.have.length(1); + expect(context.scope.conditionals?.[0].path).to.equal(form.components[1].key); + expect(context.scope.conditionals?.[0].conditionallyHidden).to.be.true; }); it('Should not define a conditional component (that condition is based on selectBoxes value) as hidden', async () => { diff --git a/src/process/conditions/index.ts b/src/process/conditions/index.ts index 874a6b79..c68a66d4 100644 --- a/src/process/conditions/index.ts +++ b/src/process/conditions/index.ts @@ -93,9 +93,6 @@ export const conditionalProcess = (context: ConditionsContext, isHidden: Conditi } conditionalComp.conditionallyHidden = conditionalComp.conditionallyHidden || isHidden(context); - if (conditionalComp.conditionallyHidden) { - set(component, 'hidden', true); - } }; export const customConditionProcess: ProcessorFn = async (context: ConditionsContext) => { diff --git a/src/process/hideChildren.ts b/src/process/hideChildren.ts index ec90a3e7..d2187e88 100644 --- a/src/process/hideChildren.ts +++ b/src/process/hideChildren.ts @@ -19,7 +19,12 @@ export const hideChildrenProcessor: ProcessorFnSync = (context) const isConditionallyHidden = scope.conditionals?.find((cond) => { return path === cond.path && cond.conditionallyHidden; }); - if (component.hidden && isConditionallyHidden) { + + if (!scope.conditionals) { + scope.conditionals = []; + } + + if (isConditionallyHidden || component.hidden) { const info = componentInfo(component); if (info.hasColumns || info.hasComps || info.hasRows) { // If this is a container component, we need to make the mutation to all the child components as well. @@ -27,17 +32,6 @@ export const hideChildrenProcessor: ProcessorFnSync = (context) if (comp !== component) { // the path set here is not the absolute path, but the path relative to the parent component (scope as ConditionsScope).conditionals?.push({ path: getComponentPath(comp, compPath), conditionallyHidden: true }); - set(comp, 'hidden', true); - } - }); - } - } else if (component.hidden) { - const info = componentInfo(component); - if (info.hasColumns || info.hasComps || info.hasRows) { - // If this is a container component, we need to make the mutation to all the child components as well. - eachComponentData([component], row, (comp: Component, data: any, compRow: any, compPath: string) => { - if (comp !== component) { - set(comp, 'hidden', true); } }); } diff --git a/src/utils/logic.ts b/src/utils/logic.ts index 96a12278..badb4860 100644 --- a/src/utils/logic.ts +++ b/src/utils/logic.ts @@ -3,7 +3,6 @@ import { checkCustomConditional, checkJsonConditional, checkLegacyConditional, c import { LogicActionCustomAction, LogicActionMergeComponentSchema, LogicActionProperty, LogicActionPropertyBoolean, LogicActionPropertyString, LogicActionValue } from "types/AdvancedLogic"; import { get, set, clone, isEqual, assign } from 'lodash'; import { evaluate, interpolate } from 'modules/jsonlogic'; -import { componentInfo, eachComponentData, getComponentPath } from "./formUtil"; export const hasLogic = (context: LogicContext): boolean => { const { component } = context; @@ -70,7 +69,6 @@ export function setActionBooleanProperty(context: LogicContext, action: LogicAct conditionallyHidden: !!component.hidden, }); } - set(component, 'hidden', !!component.hidden); } return true; }