From 682f9131a06dbdb130ced7d38710cd8d296261e3 Mon Sep 17 00:00:00 2001 From: scottqueen-bixal Date: Wed, 29 Jan 2025 06:51:48 -0500 Subject: [PATCH 1/5] PXBF-2089-fix-nested-child-errors: setTimeout 0 around getRequiredFieldsets to ensure it runs after DOM update --- .../src/shared/utils/errorHandling/index.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/benefit-finder/src/shared/utils/errorHandling/index.js b/benefit-finder/src/shared/utils/errorHandling/index.js index 3cbdf5c4..674c6a7a 100644 --- a/benefit-finder/src/shared/utils/errorHandling/index.js +++ b/benefit-finder/src/shared/utils/errorHandling/index.js @@ -5,11 +5,17 @@ * @function */ export const getRequiredFieldsets = (document, setHandler) => { - const collectedNodeList = document.querySelectorAll('fieldset') - const requiredNodeList = Array.from(collectedNodeList).filter( - node => node.attributes.required - ) - setHandler(Array.from(requiredNodeList)) + setTimeout(() => { + const collectedNodeList = document.querySelectorAll('fieldset') + console.log(collectedNodeList) + + const requiredNodeList = Array.from(collectedNodeList).filter( + node => node.attributes.required && node.hidden === false + ) + + console.log(requiredNodeList) + setHandler(Array.from(requiredNodeList)) + }, 0) } /** From 60a6ddeedcdb66c58a8e7b1a6dd34f627afaf5bb Mon Sep 17 00:00:00 2001 From: scottqueen-bixal Date: Wed, 29 Jan 2025 06:52:25 -0500 Subject: [PATCH 2/5] PXBF-2089-fix-nested-child-errors: recheck for required fields more often --- .../src/Routes/LifeEventSection/index.jsx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/benefit-finder/src/Routes/LifeEventSection/index.jsx b/benefit-finder/src/Routes/LifeEventSection/index.jsx index cfe32e64..cb8b4663 100644 --- a/benefit-finder/src/Routes/LifeEventSection/index.jsx +++ b/benefit-finder/src/Routes/LifeEventSection/index.jsx @@ -183,8 +183,10 @@ const LifeEventSection = ({ data, handleData, ui }) => { * @return {null} only executes inherited functions */ const handleBackUpdate = updateIndex => { + // allow uses to navigate back, even if there are errors formStep === 0 ? navigate(`/${ROUTES.indexPath}`) : navigate(updateIndex) resetElement.current.focus() + setHasError([]) } /** @@ -201,6 +203,7 @@ const LifeEventSection = ({ data, handleData, ui }) => { setCurrentData, event.target.value ) + errorHandling.getRequiredFieldsets(document, setRequiredFieldsets) hasError.length > 0 && errorHandling.handleCheckForRequiredValues(requiredFieldsets, setHasError) setHasData(apiCalls.GET.SelectedValueAll(data).length > 0) @@ -215,6 +218,7 @@ const LifeEventSection = ({ data, handleData, ui }) => { const handleDateChanged = (event, criteriaKey) => { // if event target is empty check if all values in date are empty window.history.replaceState({}, '', window.location.pathname) + errorHandling.getRequiredFieldsets(document, setRequiredFieldsets) async function validUpdate() { if (dateInputValidation(event) === true) { @@ -269,6 +273,7 @@ const LifeEventSection = ({ data, handleData, ui }) => { a11yTitles(location.pathname, locale) !location.hash && resetElement.current?.focus() !location.hash && window.scrollTo(0, 0) + setHasError([]) // reset error state }, [location]) useEffect(() => { @@ -560,15 +565,6 @@ const LifeEventSection = ({ data, handleData, ui }) => { item.fieldset.inputs[0].inputCriteria.type === 'Date' ? checkDateDependency(selectedParentValue) : checkFieldDependencies(selectedParentValue) - // const hidden = checkDateDependency(selectedParentValue) - // const hidden = checkFieldDependencies(selectedParentValue) - - // const hidden = - // selectedParentValue?.value !== - // item.fieldset.inputs[0].inputCriteria - // .childDependencyOption - - // console.log('hidden', hidden) return hidden } From 91ffb8821d74529e3e4d7a043d104c0cd4e39544 Mon Sep 17 00:00:00 2001 From: scottqueen-bixal Date: Wed, 29 Jan 2025 06:52:50 -0500 Subject: [PATCH 3/5] PXBF-2089-fix-nested-child-errors: update mock json to include nested child required for testing --- .../src/shared/api/mock-data/current.js | 50 +++++++++++++++++-- .../src/shared/api/mock-data/current.json | 50 +++++++++++++++++-- 2 files changed, 94 insertions(+), 6 deletions(-) diff --git a/benefit-finder/src/shared/api/mock-data/current.js b/benefit-finder/src/shared/api/mock-data/current.js index ca3e9126..0ceaaf69 100644 --- a/benefit-finder/src/shared/api/mock-data/current.js +++ b/benefit-finder/src/shared/api/mock-data/current.js @@ -45,8 +45,8 @@ const content = `{ "type": "Date", "name": "applicant_date_of_birth", "label": "Date of birth", - "hasChild": false, - "childDependencyOption": "", + "hasChild": true, + "childDependencyOption": ">=18years", "values": [ { "default": "", @@ -56,7 +56,51 @@ const content = `{ } } ], - "children": [] + "children": [ + { + "fieldsets": [ + { + "fieldset": { + "criteriaKey": "nested_child_criteria_test", + "legend": "nested_child_criteria_test", + "required": true, + "hint": "", + "inputs": [ + { + "inputCriteria": { + "id": "nested_child_criteria_test", + "type": "Select", + "name": "nested_child_criteria_test", + "label": "nested_child_criteria_test status_2", + "hasChild": false, + "childDependencyOption": "", + "values": [ + { + "option": "Married", + "value": "Married" + }, + { + "option": "Unmarried", + "value": "Unmarried" + }, + { + "option": "Widowed", + "value": "Widowed" + }, + { + "option": "Divorced", + "value": "Divorced" + } + ] + } + } + ], + "children": [] + } + } + ] + } + ] } }, { diff --git a/benefit-finder/src/shared/api/mock-data/current.json b/benefit-finder/src/shared/api/mock-data/current.json index 10a1d3b6..fa7c988a 100644 --- a/benefit-finder/src/shared/api/mock-data/current.json +++ b/benefit-finder/src/shared/api/mock-data/current.json @@ -45,8 +45,8 @@ "type": "Date", "name": "applicant_date_of_birth", "label": "Date of birth", - "hasChild": false, - "childDependencyOption": "", + "hasChild": true, + "childDependencyOption": ">=18years", "values": [ { "default": "", @@ -56,7 +56,51 @@ } } ], - "children": [] + "children": [ + { + "fieldsets": [ + { + "fieldset": { + "criteriaKey": "nested_child_criteria_test", + "legend": "nested_child_criteria_test", + "required": true, + "hint": "", + "inputs": [ + { + "inputCriteria": { + "id": "nested_child_criteria_test", + "type": "Select", + "name": "nested_child_criteria_test", + "label": "nested_child_criteria_test status_2", + "hasChild": false, + "childDependencyOption": "", + "values": [ + { + "option": "Married", + "value": "Married" + }, + { + "option": "Unmarried", + "value": "Unmarried" + }, + { + "option": "Widowed", + "value": "Widowed" + }, + { + "option": "Divorced", + "value": "Divorced" + } + ] + } + } + ], + "children": [] + } + } + ] + } + ] } }, { From 0d67d0d4d7bb8ea61c83186204942aae4812a25e Mon Sep 17 00:00:00 2001 From: scottqueen-bixal Date: Wed, 29 Jan 2025 06:53:03 -0500 Subject: [PATCH 4/5] PXBF-2089-fix-nested-child-errors: updated snapshot --- .../__snapshots__/index.spec.jsx.snap | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/benefit-finder/src/Routes/LifeEventSection/__tests__/__snapshots__/index.spec.jsx.snap b/benefit-finder/src/Routes/LifeEventSection/__tests__/__snapshots__/index.spec.jsx.snap index 4228392f..2c06a783 100644 --- a/benefit-finder/src/Routes/LifeEventSection/__tests__/__snapshots__/index.spec.jsx.snap +++ b/benefit-finder/src/Routes/LifeEventSection/__tests__/__snapshots__/index.spec.jsx.snap @@ -302,6 +302,74 @@ exports[`LifeEventSection > renders a match to the previous snapshot 1`] = ` +
+ +
From f459d7bb58f7d919676afa74460e0c6a15dae1ce Mon Sep 17 00:00:00 2001 From: scottqueen-bixal Date: Wed, 29 Jan 2025 06:54:40 -0500 Subject: [PATCH 5/5] PXBF-2089-fix-nested-child-errors: remove logs --- benefit-finder/src/shared/utils/errorHandling/index.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/benefit-finder/src/shared/utils/errorHandling/index.js b/benefit-finder/src/shared/utils/errorHandling/index.js index 674c6a7a..87a393e2 100644 --- a/benefit-finder/src/shared/utils/errorHandling/index.js +++ b/benefit-finder/src/shared/utils/errorHandling/index.js @@ -7,13 +7,9 @@ export const getRequiredFieldsets = (document, setHandler) => { setTimeout(() => { const collectedNodeList = document.querySelectorAll('fieldset') - console.log(collectedNodeList) - const requiredNodeList = Array.from(collectedNodeList).filter( node => node.attributes.required && node.hidden === false ) - - console.log(requiredNodeList) setHandler(Array.from(requiredNodeList)) }, 0) }