@@ -38,7 +38,7 @@ import {
38
38
RecordListener ,
39
39
WidgetErrors ,
40
40
} from "./types" ;
41
- import { nextId } from "./utils" ;
41
+ import { isReferenceField , nextId } from "./utils" ;
42
42
43
43
type ContextCreator = ( ) => DataContext ;
44
44
@@ -431,9 +431,17 @@ function useActionAttrs({
431
431
useCallback (
432
432
( get , set , { attrs } ) => {
433
433
const formState = get ( formAtom ) ;
434
- const isJsonScope = formState . meta . view ?. json ;
435
- const updateFormAtom = isJsonScope ? formState . parent ! : formAtom ;
436
- const updateFormState = isJsonScope ? get ( updateFormAtom ) : formState ;
434
+ const { meta } = formState ;
435
+
436
+ const schema = ( meta as any ) . schema as Schema ;
437
+ const parentFormAtom = formState . parent ! ;
438
+ const isJsonScope = meta . view ?. json ;
439
+ const isRefScope =
440
+ parentFormAtom && schema ?. name && isReferenceField ( schema ) ;
441
+
442
+ const updateFormAtom =
443
+ isJsonScope || isRefScope ? parentFormAtom : formAtom ;
444
+ const updateFormState = get ( updateFormAtom ) ;
437
445
438
446
let { statesByName } = updateFormState ;
439
447
@@ -448,6 +456,16 @@ function useActionAttrs({
448
456
const [ target , targetFieldName ] = ( ( ) => {
449
457
const { target } = attr ;
450
458
459
+ const toTargetNames = ( refName : string ) => {
460
+ return target . startsWith ( refName ! )
461
+ ? [ target , target . slice ( refName ! . length + 1 ) ]
462
+ : [ `${ refName } .${ target } ` , target ] ;
463
+ } ;
464
+
465
+ if ( isRefScope ) {
466
+ return toTargetNames ( schema . name ! ) ;
467
+ }
468
+
451
469
const isFormField = updateFormState . fields [ jsonItem ?. name ?? "" ] ;
452
470
const isOwnJsonField =
453
471
isJsonScope &&
@@ -462,10 +480,7 @@ function useActionAttrs({
462
480
target . startsWith ( jsonItem . modelField ) ||
463
481
isOwnJsonField )
464
482
) {
465
- const { modelField } = jsonItem ;
466
- return target . startsWith ( modelField ! )
467
- ? [ target , target . slice ( modelField ! . length + 1 ) ]
468
- : [ `${ modelField } .${ target } ` , target ] ;
483
+ return toTargetNames ( jsonItem . modelField ) ;
469
484
}
470
485
return [ target , target ] ;
471
486
} ) ( ) ;
0 commit comments