Skip to content

Commit

Permalink
Merge pull request #137 from formio/fix/FIO-8723_clearing_default_val…
Browse files Browse the repository at this point in the history
…ues_for_hidden_components

FIO-8723: Clear values from submission for hidden comp with clearOnHide flag
  • Loading branch information
brendanbond authored and lane-formio committed Oct 4, 2024
1 parent 0272ce5 commit 4a099c2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
3 changes: 0 additions & 3 deletions src/process/conditions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConditionsScope> = async (context: ConditionsContext) => {
Expand Down
18 changes: 6 additions & 12 deletions src/process/hideChildren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,19 @@ export const hideChildrenProcessor: ProcessorFnSync<ConditionsScope> = (context)
const isConditionallyHidden = scope.conditionals?.find((cond) => {
return path.includes(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.
eachComponentData([component], row, (comp: Component, data: any, compRow: any, compPath: string) => {
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);
}
});
}
Expand Down
2 changes: 0 additions & 2 deletions src/utils/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,7 +69,6 @@ export function setActionBooleanProperty(context: LogicContext, action: LogicAct
conditionallyHidden: !!component.hidden,
});
}
set(component, 'hidden', !!component.hidden);
}
return true;
}
Expand Down

0 comments on commit 4a099c2

Please sign in to comment.