@@ -351,7 +351,9 @@ export function useForm<
351351
352352 const validateSchema = withLatest (
353353 async ( mode : SchemaValidationMode ) => {
354- return ( await mode ) === 'silent' ? debouncedSilentValidation ( ) : debouncedValidation ( ) ;
354+ return ( await ( mode === 'silent'
355+ ? debouncedSilentValidation ( )
356+ : debouncedValidation ( ) ) ) as FormValidationResult < TValues > ;
355357 } ,
356358 ( formResult , [ mode ] ) => {
357359 // fields by id lookup
@@ -364,15 +366,19 @@ export function useForm<
364366 ] . sort ( ) as string [ ] ;
365367
366368 // aggregates the paths into a single result object while applying the results on the fields
367- return paths . reduce (
369+ const results = paths . reduce (
368370 ( validation , _path ) => {
369- const path = _path as Path < TValues > ;
370- const pathState = findPathState ( path ) || findHoistedPath ( path ) ;
371- const messages = ( formResult . results [ path ] || { errors : [ ] as string [ ] } ) . errors ;
372- const fieldResult = {
373- errors : messages ,
374- valid : ! messages . length ,
375- } ;
371+ const expectedPath = _path as Path < TValues > ;
372+ const pathState = findPathState ( expectedPath ) || findHoistedPath ( expectedPath ) ;
373+ const messages = formResult . results [ expectedPath ] ?. errors || [ ] ;
374+ // This is the real path of the field, because it might've been a hoisted field
375+ const path = ( toValue ( pathState ?. path ) || expectedPath ) as Path < TValues > ;
376+ // It is possible that multiple paths are collected across loops
377+ // We want to merge them to avoid overriding any iteration's results
378+ const fieldResult = mergeValidationResults (
379+ { errors : messages , valid : ! messages . length } ,
380+ validation . results [ path ] ,
381+ ) ;
376382 validation . results [ path ] = fieldResult ;
377383 if ( ! fieldResult . valid ) {
378384 validation . errors [ path ] = fieldResult . errors [ 0 ] ;
@@ -406,6 +412,8 @@ export function useForm<
406412 } ,
407413 { valid : formResult . valid , results : { } , errors : { } } as FormValidationResult < TValues > ,
408414 ) ;
415+
416+ return results ;
409417 } ,
410418 ) ;
411419
@@ -1183,3 +1191,14 @@ function useFormInitialValues<TValues extends GenericObject>(
11831191 setInitialValues,
11841192 } ;
11851193}
1194+
1195+ function mergeValidationResults ( a : ValidationResult , b ?: ValidationResult ) : ValidationResult {
1196+ if ( ! b ) {
1197+ return a ;
1198+ }
1199+
1200+ return {
1201+ valid : a . valid && b . valid ,
1202+ errors : [ ...a . errors , ...b . errors ] ,
1203+ } ;
1204+ }
0 commit comments