question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redux-form will unmount when a button inside the form is clicked

See original GitHub issue

Hi 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

  1. 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, the id is cleared, because of the destroyOnUnmount is True

  2. If I set the destroyOnUnmount to False, the id field is retained, but new value assigned to initialValues will not be rerendered

  3. 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

  4. 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:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
Aaroniuscommented, Dec 13, 2016

@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?

<button type="button">Button</button>

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.

2reactions
dcarr178commented, Aug 8, 2017

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">

Read more comments on GitHub >

github_iconTop Results From Across the Web

redux form - how can i show input before click add button?
I mean, when the page is first opened, the two inputs will already be shown and the user will press the button whenever...
Read more >
Why are all my buttons triggering onSubmit? - Redux Form
This can cause all buttons within your form to trigger onSubmit . ... their parent form's onSubmit handler, regardless of the button's own...
Read more >
Final Form Docs – FAQ
FAQ. Below are some frequently asked questions. Why not Redux-Form or Formik? Those are both excellent form libraries. Like all engineering decisions, ...
Read more >
FAQs | React Hook Form - Simple React forms validation
You can't use Hooks inside of a class component, but you can definitely mix classes ... This method does the same thing as...
Read more >
22) Redux form - Learn React js in Tamil - YouTube
22) Redux form - initializing a form and disabling button on submit ... How to disable submit button when form submission is in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found