@@ -102,24 +102,26 @@ function evaluateFieldDependents(field: FormField, values: any, context: FormCon
102102 evaluateExpression ,
103103 updateFormField ,
104104 ) ;
105- targetSection . questions = targetSection ?. questions . map ( ( question ) => {
106- if ( question . id === dependent . id ) {
107- return dependent ;
108- }
109- return question ;
110- } ) ;
111105
112- const isDependentFieldHidden = dependent . isHidden ;
113- const sectionHasVisibleFieldAfterEvaluation = [ ...targetSection . questions , dependent ] . some (
114- ( field ) => ! field . isHidden ,
115- ) ;
106+ if ( targetSection ) {
107+ targetSection . questions = targetSection ?. questions . map ( ( question ) => {
108+ if ( question . id === dependent . id ) {
109+ return dependent ;
110+ }
111+ return question ;
112+ } ) ;
113+ const isDependentFieldHidden = dependent . isHidden ;
114+ const sectionHasVisibleFieldAfterEvaluation = [ ...targetSection . questions , dependent ] . some (
115+ ( field ) => ! field . isHidden ,
116+ ) ;
116117
117- if ( ! isSectionVisible && ! isDependentFieldHidden ) {
118- targetSection . isHidden = false ;
119- shouldUpdateForm = true ;
120- } else if ( isSectionVisible && ! sectionHasVisibleFieldAfterEvaluation ) {
121- targetSection . isHidden = true ;
122- shouldUpdateForm = true ;
118+ if ( ! isSectionVisible && ! isDependentFieldHidden ) {
119+ targetSection . isHidden = false ;
120+ shouldUpdateForm = true ;
121+ } else if ( isSectionVisible && ! sectionHasVisibleFieldAfterEvaluation ) {
122+ targetSection . isHidden = true ;
123+ shouldUpdateForm = true ;
124+ }
123125 }
124126 }
125127 // evaluate disabled
0 commit comments