Skip to content

Commit

Permalink
Merge pull request #1283 from GSA/1108-clear-child-field-groups
Browse files Browse the repository at this point in the history
Remove hidden values in child inputs
  • Loading branch information
scottqueen-bixal authored May 6, 2024
2 parents 925505b + 29e0b14 commit 02025a2
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions benefit-finder/src/shared/components/LifeEventSection/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
})
)
})
),
})
}
Expand Down

0 comments on commit 02025a2

Please sign in to comment.