@@ -567,7 +567,11 @@ function NormalArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
567567 const canAdd = canAddItem < T , S , F > ( registry , schema , formData , uiSchema ) && ( ! renderOptionalField || hasFormData ) ;
568568 const actualFormData = hasFormData ? keyedFormData : [ ] ;
569569 const extraClass = renderOptionalField ? ' rjsf-optional-array-field' : '' ;
570- const optionalDataControl = renderOptionalField ? < OptionalDataControlsField { ...props } /> : undefined ;
570+ // All the children will use childFieldPathId if present in the props, falling back to the fieldPathId
571+ const childFieldPathId = props . childFieldPathId ?? fieldPathId ;
572+ const optionalDataControl = renderOptionalField ? (
573+ < OptionalDataControlsField { ...props } fieldPathId = { childFieldPathId } />
574+ ) : undefined ;
571575 const arrayProps : ArrayFieldTemplateProps < T [ ] , S , F > = {
572576 canAdd,
573577 items : actualFormData . map ( ( keyedItem , index : number ) => {
@@ -576,7 +580,7 @@ function NormalArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
576580 const itemCast = item as unknown as T [ ] ;
577581 const itemSchema = schemaUtils . retrieveSchema ( _schemaItems , itemCast ) ;
578582 const itemErrorSchema = errorSchema ? ( errorSchema [ index ] as ErrorSchema < T [ ] > ) : undefined ;
579- const itemFieldPathId = toFieldPathId ( index , globalFormOptions , fieldPathId ) ;
583+ const itemFieldPathId = toFieldPathId ( index , globalFormOptions , childFieldPathId ) ;
580584
581585 // Compute the item UI schema using the helper method
582586 const itemUiSchema = computeItemUiSchema < T , S , F > ( uiSchema , item , index , formContext ) ;
@@ -675,14 +679,18 @@ function FixedArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
675679 const additionalSchema = isObject ( schema . additionalItems )
676680 ? schemaUtils . retrieveSchema ( schema . additionalItems as S , formData )
677681 : null ;
682+ // All the children will use childFieldPathId if present in the props, falling back to the fieldPathId
683+ const childFieldPathId = props . childFieldPathId ?? fieldPathId ;
678684
679685 if ( items . length < itemSchemas . length ) {
680686 // to make sure at least all fixed items are generated
681687 items = items . concat ( new Array ( itemSchemas . length - items . length ) ) ;
682688 }
683689 const actualFormData = hasFormData ? keyedFormData : [ ] ;
684690 const extraClass = renderOptionalField ? ' rjsf-optional-array-field' : '' ;
685- const optionalDataControl = renderOptionalField ? < OptionalDataControlsField { ...props } /> : undefined ;
691+ const optionalDataControl = renderOptionalField ? (
692+ < OptionalDataControlsField { ...props } fieldPathId = { childFieldPathId } />
693+ ) : undefined ;
686694
687695 // These are the props passed into the render function
688696 const canAdd =
@@ -704,7 +712,7 @@ function FixedArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
704712 ( additional && isObject ( schema . additionalItems )
705713 ? schemaUtils . retrieveSchema ( schema . additionalItems as S , itemCast )
706714 : itemSchemas [ index ] ) || { } ;
707- const itemFieldPathId = toFieldPathId ( index , globalFormOptions , fieldPathId ) ;
715+ const itemFieldPathId = toFieldPathId ( index , globalFormOptions , childFieldPathId ) ;
708716 // Compute the item UI schema - handle both static and dynamic cases
709717 let itemUiSchema : UiSchema < T [ ] , S , F > | undefined ;
710718 if ( additional ) {
@@ -834,6 +842,8 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
834842 const { schema, uiSchema, errorSchema, fieldPathId, registry, formData, onChange } = props ;
835843 const { schemaUtils, translateString } = registry ;
836844 const { keyedFormData, updateKeyedFormData } = useKeyedFormData < T > ( formData ) ;
845+ // All the children will use childFieldPathId if present in the props, falling back to the fieldPathId
846+ const childFieldPathId = props . childFieldPathId ?? fieldPathId ;
837847
838848 /** Callback handler for when the user clicks on the add or add at index buttons. Creates a new row of keyed form data
839849 * either at the end of the list (when index is not specified) or inserted at the `index` when it is, adding it into
@@ -871,9 +881,9 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
871881 } else {
872882 newKeyedFormData . push ( newKeyedFormDataRow ) ;
873883 }
874- onChange ( updateKeyedFormData ( newKeyedFormData ) , fieldPathId . path , newErrorSchema as ErrorSchema < T [ ] > ) ;
884+ onChange ( updateKeyedFormData ( newKeyedFormData ) , childFieldPathId . path , newErrorSchema as ErrorSchema < T [ ] > ) ;
875885 } ,
876- [ keyedFormData , registry , schema , onChange , updateKeyedFormData , errorSchema , fieldPathId ] ,
886+ [ keyedFormData , registry , schema , onChange , updateKeyedFormData , errorSchema , childFieldPathId ] ,
877887 ) ;
878888
879889 /** Callback handler for when the user clicks on the copy button on an existing array element. Clones the row of
@@ -911,9 +921,9 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
911921 } else {
912922 newKeyedFormData . push ( newKeyedFormDataRow ) ;
913923 }
914- onChange ( updateKeyedFormData ( newKeyedFormData ) , fieldPathId . path , newErrorSchema as ErrorSchema < T [ ] > ) ;
924+ onChange ( updateKeyedFormData ( newKeyedFormData ) , childFieldPathId . path , newErrorSchema as ErrorSchema < T [ ] > ) ;
915925 } ,
916- [ keyedFormData , onChange , updateKeyedFormData , errorSchema , fieldPathId ] ,
926+ [ keyedFormData , onChange , updateKeyedFormData , errorSchema , childFieldPathId ] ,
917927 ) ;
918928
919929 /** Callback handler for when the user clicks on the remove button on an existing array element. Removes the row of
@@ -941,9 +951,9 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
941951 }
942952 }
943953 const newKeyedFormData = keyedFormData . filter ( ( _ , i ) => i !== index ) ;
944- onChange ( updateKeyedFormData ( newKeyedFormData ) , fieldPathId . path , newErrorSchema as ErrorSchema < T [ ] > ) ;
954+ onChange ( updateKeyedFormData ( newKeyedFormData ) , childFieldPathId . path , newErrorSchema as ErrorSchema < T [ ] > ) ;
945955 } ,
946- [ keyedFormData , onChange , updateKeyedFormData , errorSchema , fieldPathId ] ,
956+ [ keyedFormData , onChange , updateKeyedFormData , errorSchema , childFieldPathId ] ,
947957 ) ;
948958
949959 /** Callback handler for when the user clicks on one of the move item buttons on an existing array element. Moves the
@@ -985,9 +995,9 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
985995 return _newKeyedFormData ;
986996 }
987997 const newKeyedFormData = reOrderArray ( ) ;
988- onChange ( updateKeyedFormData ( newKeyedFormData ) , fieldPathId . path , newErrorSchema as ErrorSchema < T [ ] > ) ;
998+ onChange ( updateKeyedFormData ( newKeyedFormData ) , childFieldPathId . path , newErrorSchema as ErrorSchema < T [ ] > ) ;
989999 } ,
990- [ keyedFormData , onChange , updateKeyedFormData , errorSchema , fieldPathId ] ,
1000+ [ keyedFormData , onChange , updateKeyedFormData , errorSchema , childFieldPathId ] ,
9911001 ) ;
9921002
9931003 /** Callback handler used to deal with changing the value of the data in the array at the `index`. Calls the
@@ -1012,9 +1022,9 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
10121022 /** Callback handler used to change the value for a checkbox */
10131023 const onSelectChange = useCallback (
10141024 ( value : any ) => {
1015- onChange ( value , fieldPathId . path , undefined , fieldPathId ?. [ ID_KEY ] ) ;
1025+ onChange ( value , childFieldPathId . path , undefined , childFieldPathId ?. [ ID_KEY ] ) ;
10161026 } ,
1017- [ onChange , fieldPathId ] ,
1027+ [ onChange , childFieldPathId ] ,
10181028 ) ;
10191029
10201030 if ( ! ( ITEMS_KEY in schema ) ) {
@@ -1044,16 +1054,16 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
10441054 } ;
10451055 if ( schemaUtils . isMultiSelect ( schema ) ) {
10461056 // If array has enum or uniqueItems set to true, call renderMultiSelect() to render the default multiselect widget or a custom widget, if specified.
1047- return < ArrayAsMultiSelect < T , S , F > { ...props } onSelectChange = { onSelectChange } /> ;
1057+ return < ArrayAsMultiSelect < T , S , F > { ...props } fieldPathId = { childFieldPathId } onSelectChange = { onSelectChange } /> ;
10481058 }
10491059 if ( isCustomWidget < T [ ] , S , F > ( uiSchema ) ) {
1050- return < ArrayAsCustomWidget < T , S , F > { ...props } onSelectChange = { onSelectChange } /> ;
1060+ return < ArrayAsCustomWidget < T , S , F > { ...props } fieldPathId = { childFieldPathId } onSelectChange = { onSelectChange } /> ;
10511061 }
10521062 if ( isFixedItems ( schema ) ) {
10531063 return < FixedArray < T , S , F > { ...props } { ...arrayProps } /> ;
10541064 }
10551065 if ( schemaUtils . isFilesArray ( schema , uiSchema ) ) {
1056- return < ArrayAsFiles { ...props } onSelectChange = { onSelectChange } /> ;
1066+ return < ArrayAsFiles { ...props } fieldPathId = { childFieldPathId } onSelectChange = { onSelectChange } /> ;
10571067 }
10581068 return < NormalArray < T , S , F > { ...props } { ...arrayProps } /> ;
10591069}
0 commit comments