From 29e0b141d1524ee2e3bbfb99bbded8275e3db48c Mon Sep 17 00:00:00 2001 From: scottqueen-bixal Date: Mon, 6 May 2024 11:45:55 -0400 Subject: [PATCH] PXBF-1108-clear-child-field-groups: remove hidden values in child inputs --- .../components/LifeEventSection/index.jsx | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/benefit-finder/src/shared/components/LifeEventSection/index.jsx b/benefit-finder/src/shared/components/LifeEventSection/index.jsx index a0053f990..77dc9f8ea 100644 --- a/benefit-finder/src/shared/components/LifeEventSection/index.jsx +++ b/benefit-finder/src/shared/components/LifeEventSection/index.jsx @@ -482,6 +482,11 @@ const LifeEventSection = ({ const checkParentValue = item => { const selectedParentValue = apiCalls.GET.SelectedValue(item) + /** + * a value that checks the selected parent validator to expose child inputs in the form + * @return {boolean} returns true or false + */ + const hidden = selectedParentValue?.value !== item.fieldset.inputs[0].inputCriteria @@ -497,13 +502,26 @@ const LifeEventSection = ({ children: item.fieldset.children.map( (child, i) => child.fieldsets.length && - child.fieldsets.map((childItem, childItemIndex) => - Input({ + child.fieldsets.map((childItem, childItemIndex) => { + // if a parent determines the children inputs are hidden, we expect that the seleted values in child items are de-selected + const selectedValue = + childItem && apiCalls.GET.SelectedValue(childItem) + + const isHidden = checkParentValue(item) + + if ( + isHidden === true && + selectedValue !== undefined + ) { + delete selectedValue.selected + } + + return Input({ item: childItem, index: childItemIndex, - hidden: checkParentValue(item), + hidden: isHidden, }) - ) + }) ), }) }