Redux-form will unmount when a button inside the form is clicked
See original GitHub issueHi I am wondering if there is a way to stop the form from unmounting itself when a button is clicked inside the form (even though the button is not the submit button)
my current use case is :
when user fill in the id
field, he can click on a button like “find info” to query the backend and auto populate some fields of the form
my problem are
-
In normal case, I can get my form to be updated by setting the
initialValues
props with the new value returned from api call. However, due to the unmounting issue, theid
is cleared, because of thedestroyOnUnmount
is True -
If I set the
destroyOnUnmount
to False, theid
field is retained, but new value assigned toinitialValues
will not be rerendered -
Some of my fields inside the form are using react-select async, so everytime the form is unmounted and mounted, the react-select will trigger the api call, which is not necessary https://github.com/JedWatson/react-select/issues/1369
-
Because of the unmounting, everytime when user fill up the form and click submit, if there is an error, all the input will be lost (cleared)
and also, upon reading this issue https://github.com/erikras/redux-form/issues/145 , seems like reducer plugin is the correct way to perform the auto update action ?
Thanks !
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
Top GitHub Comments
@ripitrust This might be obvious and you may already know about it, but it’s a bugger when you don’t know or forget: is your button like this?
If it doesn’t have
type="button"
then it defaults to being a submit button. It sounds like in this case you don’t want a submit button.On latest redux-form, the form unmounts on me when I add
<button>
without a type but works fine if I use<button type="button">