Setting multiple form fields
I am trying to set multiple form fields from an async typeahead. A good example of this might be an address typeahead where the address fields are set upon user selection. I have a field group implemented via
withFieldGroup where I am using group.setFieldValue to set everything on select. I haven't quite figured out how to handle the field meta values and I am unsure if this is even a reasonable approach. Is there an idiomatic way of doing this?7 Replies
genetic-orangeOP•2mo ago
Let me rephrase the question - is there a recommended way of setting multiple hidden field values when one input changes outside of
setFieldValue?like-gold•2mo ago
and if a user has already changed address fields and then switches the user? what happens then?
genetic-orangeOP•2mo ago
Im not sure I am following. In this example, if a new address is selected, it would update the address fields while overwriting what was previously set.
like-gold•2mo ago
and the user has control over those updated address fields?
but will lose unsaved changes if they change the selection field
genetic-orangeOP•2mo ago
I mean control in that they can select a new address. I suppose the answer to the second question in no - or at least I hope that if a new address is selected that they will not lose unsaved changes.
like-gold•2mo ago
in that case, I‘d put the address selection outside of form state. Have the form use derived defaultValues, which will update the fields as long as the form isn‘t touched
once the user changes something and the form is touched, it will no longer overwrite what users wrote
genetic-orangeOP•2mo ago
Thanks for the help - I appreciate it