How to change one form from another form. react-final-form

230 views Asked by At

React-final-form has problems with updating one form from another (outside of first) form. Did not find any great solution around. Example: There is 1 and 2 forms. One field from 1 form has to change after some field changed in 2 form.

I tried:

Send "form" variable from component render to redux store, then take it in the 2 form, and use its actions like "form.change('fieldFrom1Form', 'newValue'); Example

1 form:

<Form onSubmit={onSubmit} keepDirtyOnReinitialize>
      {({ handleSubmit, dirty, pristine, invalid, values, form }) => {

return (
   <FormStateToRedux form={form} /> // send your "form" var to the store in this component
)
}}

2 form: And after it, i took my "form" from store in 2 form and tried to call the "form.change()" function.

And it does not work. These actions don't let you call them outside of the <Form></Form>

1

There are 1 answers

0
Adi Dasler On

Working solution was calling form api inside of the nested custom component:

enter image description here