Updating a specific form value in an array field?
Hi! I have an array of fields (let's call them "people") and for each person I have an autocomplete that the user can use to select the person's location. There's a mutation that's called whenever the form field updates, which then displays a list of suggestions, but I'm not sure what the recommended approach is to having the suggestion selection set the location for the current person. What would y'all suggest for this?
3 Replies
correct-apricotOP•6mo ago
I solved this by just embedding the autocompletion suggestions in the
subField
closure (via the form.Field
component ). Not sure if this is what is "best practice" but it works!multiple-amethyst•6mo ago
Sounds good 👍 can you show some code?
correct-apricotOP•6mo ago
@ksgn here you go! https://github.com/dlo/tanstack-form-autocomplete-array
the good stuff is in https://github.com/dlo/tanstack-form-autocomplete-array/blob/main/src/routes/form.tsx
GitHub
GitHub - dlo/tanstack-form-autocomplete-array
Contribute to dlo/tanstack-form-autocomplete-array development by creating an account on GitHub.
GitHub
tanstack-form-autocomplete-array/src/routes/form.tsx at main · dlo/...
Contribute to dlo/tanstack-form-autocomplete-array development by creating an account on GitHub.