@@ -7,7 +7,7 @@ import set from 'lodash/set';
77import  {  lazy  }  from  'yup' ; 
88
99import  {  checkIfConditionMatchesProperties  }  from  './internals/checkIfConditionMatches' ; 
10- import  {  supportedTypes ,   getInputType  }  from  './internals/fields' ; 
10+ import  {  supportedTypes  }  from  './internals/fields' ; 
1111import  {  pickXKey  }  from  './internals/helpers' ; 
1212import  {  processJSONLogicNode  }  from  './jsonLogic' ; 
1313import  {  hasProperty  }  from  './utils' ; 
@@ -161,7 +161,7 @@ function getPrefillSubFieldValues(field, defaultValues, parentFieldKeyPath) {
161161      initialValue [ field . name ]  =  subFieldValues ; 
162162    } 
163163  }  else  { 
164-     // getDefaultValues and getPrefillSubFieldValues have a circluar  dependency, resulting in one having to be used before defined. 
164+     // getDefaultValues and getPrefillSubFieldValues have a circular  dependency, resulting in one having to be used before defined. 
165165    // As function declarations are hoisted this should not be a problem. 
166166    // eslint-disable-next-line no-use-before-define 
167167
@@ -295,6 +295,7 @@ function updateField(field, requiredFields, node, formValues, logic, config) {
295295      isRequired : fieldIsRequired , 
296296      conditionBranch : node , 
297297      formValues, 
298+       currentField : field , 
298299    } ) ; 
299300    updateAttributes ( newAttributes ) ; 
300301    removeConditionalStaleAttributes ( field ,  newAttributes ,  rootFieldAttrs ) ; 
@@ -336,9 +337,22 @@ export function processNode({
336337  const  requiredFields  =  new  Set ( accRequired ) ; 
337338
338339  // Go through the node properties definition and update each field accordingly 
339-   Object . keys ( node . properties  ??  [ ] ) . forEach ( ( fieldName )  =>  { 
340+   Object . entries ( node . properties  ??  [ ] ) . forEach ( ( [ fieldName ,   nestedNode ] )  =>  { 
340341    const  field  =  getField ( fieldName ,  formFields ) ; 
341342    updateField ( field ,  requiredFields ,  node ,  formValues ,  logic ,  {  parentID } ) ; 
343+ 
344+     // If we're processing a fieldset field node 
345+     // update the nested fields going through the node recursively. 
346+     const  isFieldset  =  field ?. inputType  ===  supportedTypes . FIELDSET ; 
347+     if  ( isFieldset )  { 
348+       processNode ( { 
349+         node : nestedNode , 
350+         formValues : formValues [ fieldName ]  ||  { } , 
351+         formFields : field . fields , 
352+         parentID, 
353+         logic, 
354+       } ) ; 
355+     } 
342356  } ) ; 
343357
344358  // Update required fields based on the `required` property and mutate node if needed 
@@ -351,7 +365,7 @@ export function processNode({
351365
352366  if  ( node . if  !==  undefined )  { 
353367    const  matchesCondition  =  checkIfConditionMatchesProperties ( node ,  formValues ,  formFields ,  logic ) ; 
354-     // BUG HERE (unreleated ) - what if it matches but doesn't has a then, 
368+     // BUG HERE (unrelated ) - what if it matches but doesn't has a then, 
355369    // it should do nothing, but instead it jumps to node.else when it shouldn't. 
356370    if  ( matchesCondition  &&  node . then )  { 
357371      const  {  required : branchRequired  }  =  processNode ( { 
@@ -408,22 +422,6 @@ export function processNode({
408422      } ) ; 
409423  } 
410424
411-   if  ( node . properties )  { 
412-     Object . entries ( node . properties ) . forEach ( ( [ name ,  nestedNode ] )  =>  { 
413-       const  inputType  =  getInputType ( nestedNode ) ; 
414-       if  ( inputType  ===  supportedTypes . FIELDSET )  { 
415-         // It's a fieldset, which might contain scoped conditions 
416-         processNode ( { 
417-           node : nestedNode , 
418-           formValues : formValues [ name ]  ||  { } , 
419-           formFields : getField ( name ,  formFields ) . fields , 
420-           parentID : name , 
421-           logic, 
422-         } ) ; 
423-       } 
424-     } ) ; 
425-   } 
426- 
427425  if  ( node [ 'x-jsf-logic' ] )  { 
428426    const  {  required : requiredFromLogic  }  =  processJSONLogicNode ( { 
429427      node : node [ 'x-jsf-logic' ] , 
@@ -451,14 +449,14 @@ export function processNode({
451449function  clearValuesIfNotVisible ( fields ,  formValues )  { 
452450  fields . forEach ( ( {  isVisible =  true ,  name,  inputType,  fields : nestedFields  } )  =>  { 
453451    if  ( ! isVisible )  { 
454-       // TODO I (Sandrina) think this doesn't work. I didn't find any test covering this scenario. Revisit later. 
455452      formValues [ name ]  =  null ; 
456453    } 
457454    if  ( inputType  ===  supportedTypes . FIELDSET  &&  nestedFields  &&  formValues [ name ] )  { 
458455      clearValuesIfNotVisible ( nestedFields ,  formValues [ name ] ) ; 
459456    } 
460457  } ) ; 
461458} 
459+ 
462460/** 
463461 * Updates form fields properties based on the current form state and the JSON schema rules 
464462 * 
@@ -500,7 +498,7 @@ function getFieldOptions(node, presentation) {
500498    } ) ) ; 
501499  } 
502500
503-   /** @deprecated  - takes precendence  in case a JSON Schema still has deprecated options */ 
501+   /** @deprecated  - takes precedence  in case a JSON Schema still has deprecated options */ 
504502  if  ( presentation . options )  { 
505503    return  presentation . options ; 
506504  } 
0 commit comments