@@ -12,7 +12,7 @@ import { gridColumnClasses, prefixId } from './Util';
1212const noop = ( ) => false ;
1313
1414export function FormField ( props ) {
15- const { field, indexes, onChange } = props ;
15+ const { field, indexes, onChange : _onChange } = props ;
1616
1717 const formFields = useService ( 'formFields' ) ,
1818 viewerCommands = useService ( 'viewerCommands' , false ) ,
@@ -53,21 +53,26 @@ export function FormField(props) {
5353
5454 const hidden = useCondition ( ( field . conditional && field . conditional . hide ) || null ) ;
5555
56+ const fieldInstance = useMemo (
57+ ( ) => ( {
58+ id : field . id ,
59+ expressionContextInfo : localExpressionContext ,
60+ valuePath,
61+ indexes,
62+ } ) ,
63+ [ field . id , valuePath , localExpressionContext , indexes ] ,
64+ ) ;
65+
5666 // register form field instance
5767 useEffect ( ( ) => {
5868 if ( formFieldInstanceRegistry && ! hidden ) {
59- const instanceId = formFieldInstanceRegistry . add ( {
60- id : field . id ,
61- expressionContextInfo : localExpressionContext ,
62- valuePath,
63- indexes,
64- } ) ;
69+ const instanceId = formFieldInstanceRegistry . add ( fieldInstance ) ;
6570
6671 return ( ) => {
6772 formFieldInstanceRegistry . remove ( instanceId ) ;
6873 } ;
6974 }
70- } , [ formFieldInstanceRegistry , field . id , localExpressionContext , valuePath , indexes , hidden ] ) ;
75+ } , [ fieldInstance , formFieldInstanceRegistry , hidden ] ) ;
7176
7277 // ensures the initial validation behavior can be re-triggered upon form reset
7378 useEffect ( ( ) => {
@@ -112,15 +117,16 @@ export function FormField(props) {
112117 eventBus . fire ( 'formField.focus' , { formField : field } ) ;
113118 } , [ eventBus , field ] ) ;
114119
115- const onChangeIndexed = useCallback (
120+ const onChange = useCallback (
116121 ( update ) => {
117- // any data change will trigger validation
118- setInitialValidationTrigger ( false ) ;
122+ if ( ! fieldConfig . keyed ) {
123+ return ;
124+ }
119125
120- // add indexes of the keyed field to the update, if any
121- onChange ( fieldConfig . keyed ? { ...update , indexes } : update ) ;
126+ setInitialValidationTrigger ( false ) ;
127+ _onChange ( { ...update , field , indexes, fieldInstance } ) ;
122128 } ,
123- [ onChange , fieldConfig . keyed , indexes ] ,
129+ [ _onChange , field , fieldConfig . keyed , fieldInstance , indexes ] ,
124130 ) ;
125131
126132 if ( hidden ) {
@@ -136,7 +142,7 @@ export function FormField(props) {
136142 disabled = { disabled }
137143 errors = { fieldErrors }
138144 domId = { domId }
139- onChange = { disabled || readonly ? noop : onChangeIndexed }
145+ onChange = { disabled || readonly ? noop : onChange }
140146 onBlur = { disabled || readonly ? noop : onBlur }
141147 onFocus = { disabled || readonly ? noop : onFocus }
142148 readonly = { readonly }
0 commit comments