Sync values from one field to others in fieldArray #12470
Unanswered
y-wertz-priomold
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Problem
I'm using field array to track multiple positions in an enquiry (each line is a field).
On the left I have checkbox to enable sync from one field to alle others that are enabled.
What I want
If the user changes "Material" in Pos 10 I want to automatically set Material of Pos 20 to the same value (if checkbox is enabled).
Thoughts
I wrapped my head around using watch, but using watch I only know some value of the form has changed and not which value has changed.
Using watch with a specific field name is not possible because of the parent field array.
For example the name of Material field is
pos.${index}.material
.I tried making a onChange sync callback at the parent / form level which could be passed to each field, but even accessing the field dynamically seems to possible.
I'm getting this typescript error (which make sense because passing a string can be an invalid field name)
Help needed
Anyone ideas how to make this work?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions