77 ArrayInputBase ,
88 type ArrayInputBaseProps ,
99} from 'ra-core' ;
10- import { useFormContext , useFormState } from 'react-hook-form' ;
10+ import { useFormContext } from 'react-hook-form' ;
1111import {
1212 InputLabel ,
1313 FormControl ,
@@ -89,23 +89,25 @@ export const ArrayInput = (inProps: ArrayInputProps) => {
8989 const parentSourceContext = useSourceContext ( ) ;
9090 const finalSource = parentSourceContext . getSource ( arraySource ) ;
9191 const { subscribe } = useFormContext ( ) ;
92- const { isSubmitted } = useFormState ( ) ;
93- const [ { error, hasBeenInteractedWith } , setArrayInputState ] =
92+ const [ { error, hasBeenInteractedWith, isSubmitted } , setArrayInputState ] =
9493 React . useState < {
9594 error : any ;
9695 hasBeenInteractedWith : boolean ;
96+ isSubmitted : boolean ;
9797 } > ( {
9898 error : undefined ,
9999 hasBeenInteractedWith : false ,
100+ isSubmitted : false ,
100101 } ) ;
101102 React . useEffect ( ( ) => {
102103 return subscribe ( {
103104 formState : {
104105 dirtyFields : true ,
105106 errors : true ,
107+ isSubmitted : true ,
106108 touchedFields : true ,
107109 } ,
108- callback : ( { dirtyFields, errors, touchedFields } ) => {
110+ callback : ( { dirtyFields, errors, isSubmitted , touchedFields } ) => {
109111 const error = get ( errors ?? { } , finalSource ) ;
110112 const hasBeenInteractedWith =
111113 get ( dirtyFields ?? { } , finalSource , false ) !== false ||
@@ -115,17 +117,18 @@ export const ArrayInput = (inProps: ArrayInputProps) => {
115117 isEqual ( previousState , {
116118 error,
117119 hasBeenInteractedWith,
120+ isSubmitted : ! ! isSubmitted ,
118121 } )
119122 ? previousState
120123 : {
121124 error,
122125 hasBeenInteractedWith,
126+ isSubmitted : ! ! isSubmitted ,
123127 }
124128 ) ;
125129 } ,
126130 } ) ;
127131 } , [ finalSource , subscribe ] ) ;
128-
129132 const displayedError =
130133 hasBeenInteractedWith || isSubmitted ? error : undefined ;
131134 const displayedErrorMessage = ( displayedError ?. root ?. message ??
0 commit comments