@@ -330,6 +330,7 @@ export function processNode({
330
330
accRequired = new Set ( ) ,
331
331
parentID = 'root' ,
332
332
logic,
333
+ processingConditional = false ,
333
334
} ) {
334
335
// Set initial required fields
335
336
const requiredFields = new Set ( accRequired ) ;
@@ -338,6 +339,24 @@ export function processNode({
338
339
Object . keys ( node . properties ?? [ ] ) . forEach ( ( fieldName ) => {
339
340
const field = getField ( fieldName , formFields ) ;
340
341
updateField ( field , requiredFields , node , formValues , logic , { parentID } ) ;
342
+
343
+ // If we're processing a conditional field node and it's respective to a fieldset field,
344
+ // update the nested fields going through the node recursively.
345
+ // As an example, the node here can be:
346
+ // 1. { properties: { perks: { properties: { retirement: { const: 'basic' } } } } } }
347
+ // 2. { properties: { perks: { required: ['retirement'] } } } }
348
+ // where 'perks' is a fieldset field.
349
+ const nestedNode = node . properties [ fieldName ] ;
350
+ const isFieldset = field ?. inputType === supportedTypes . FIELDSET ;
351
+ if ( isFieldset && processingConditional ) {
352
+ processNode ( {
353
+ node : nestedNode ,
354
+ formValues : formValues [ fieldName ] || { } ,
355
+ formFields : field . fields ,
356
+ parentID,
357
+ logic,
358
+ } ) ;
359
+ }
341
360
} ) ;
342
361
343
362
// Update required fields based on the `required` property and mutate node if needed
@@ -360,6 +379,7 @@ export function processNode({
360
379
accRequired : requiredFields ,
361
380
parentID,
362
381
logic,
382
+ processingConditional : true ,
363
383
} ) ;
364
384
365
385
branchRequired . forEach ( ( field ) => requiredFields . add ( field ) ) ;
@@ -371,6 +391,7 @@ export function processNode({
371
391
accRequired : requiredFields ,
372
392
parentID,
373
393
logic,
394
+ processingConditional : true ,
374
395
} ) ;
375
396
branchRequired . forEach ( ( field ) => requiredFields . add ( field ) ) ;
376
397
}
@@ -390,6 +411,22 @@ export function processNode({
390
411
} ) ;
391
412
}
392
413
414
+ if ( node . properties ) {
415
+ Object . entries ( node . properties ) . forEach ( ( [ name , nestedNode ] ) => {
416
+ const inputType = getInputType ( nestedNode ) ;
417
+ if ( inputType === supportedTypes . FIELDSET ) {
418
+ // It's a fieldset, which might contain scoped conditions
419
+ processNode ( {
420
+ node : nestedNode ,
421
+ formValues : formValues [ name ] || { } ,
422
+ formFields : getField ( name , formFields ) . fields ,
423
+ parentID : name ,
424
+ logic,
425
+ } ) ;
426
+ }
427
+ } ) ;
428
+ }
429
+
393
430
if ( node . allOf ) {
394
431
node . allOf
395
432
. map ( ( allOfNode ) =>
@@ -407,22 +444,6 @@ export function processNode({
407
444
} ) ;
408
445
}
409
446
410
- if ( node . properties ) {
411
- Object . entries ( node . properties ) . forEach ( ( [ name , nestedNode ] ) => {
412
- const inputType = getInputType ( nestedNode ) ;
413
- if ( inputType === supportedTypes . FIELDSET ) {
414
- // It's a fieldset, which might contain scoped conditions
415
- processNode ( {
416
- node : nestedNode ,
417
- formValues : formValues [ name ] || { } ,
418
- formFields : getField ( name , formFields ) . fields ,
419
- parentID : name ,
420
- logic,
421
- } ) ;
422
- }
423
- } ) ;
424
- }
425
-
426
447
if ( node [ 'x-jsf-logic' ] ) {
427
448
const { required : requiredFromLogic } = processJSONLogicNode ( {
428
449
node : node [ 'x-jsf-logic' ] ,
0 commit comments