Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form reset does not reset checkboxes when using enableReinitialize #1819

Closed
romandecker opened this issue Sep 16, 2019 · 6 comments
Closed
Labels

Comments

@romandecker
Copy link

🐛 Bug report

Current Behavior

Check this minimal example: https://codesandbox.io/s/formik-checkbox-reset-zyvpd

  1. Change textbox and tick checkbox
  2. Click "Submit" to update the initial values, the form should now reset to the updated values
  3. Click "Reset"

Right now, this will correctly reset the textbox, but not the checkbox!

Expected behavior

The checkbox should also be reset to the updated initial value

Reproducible example

https://codesandbox.io/s/formik-checkbox-reset-zyvpd

Your environment

Software Version(s)
Formik 1.5.8
React 16.8.6
TypeScript 3.6.3
Browser Chrome 77.0.3865.75, Firefox 69.0
npm/Yarn 1.12.3
Operating System macOS Mojave 10.14.6
@stale stale bot added the stale label Nov 15, 2019
@maheshsundaram
Copy link

I'm having this same issue. @DEX3 had you figured out any way to workaround it?

@stale stale bot removed the stale label Feb 25, 2020
@romandecker
Copy link
Author

Nope, we couldn't make reset to work properly, the issue solved itself for us when we started re-rendering the entire <Formik />-container on reset. The underlying issue still persists however.

@Gibbo3771
Copy link

Gibbo3771 commented Feb 26, 2020

Having some problem. I have a bunch of custom multi-step forms and on the final step of these forms, you are able to submit the form, but at the end you can also submit and reset, going back to step one.

Calling formik.resetForm() passed in via render props never resets checkboxes or radio buttons. Only text feilds.

@DEX3 How are you resetting the form? I don't see anywhere to force a re-render with Formik. Are you just using useEffect?

@stale stale bot added the stale label Apr 26, 2020
@maddhruv
Copy link
Collaborator

maddhruv commented Nov 9, 2020

Try the latest formik (>= 2.2.3), fixed with #2874

@SomeFanatic
Copy link

Well, easiest workaround is using: document.getElementById("gdprId").checked = false;
I'm using formik 2.2.9 and the issue is still not fixed.

    onSubmit: (values, {resetForm}) => {
        setDisplayMessage("animate");
        values.created_on = new Date().getTime();
        values.created_on_dv = Date();
        postToDb('contact_form', values);

         resetForm({});
         document.getElementById("gdprId").checked = false;

    },

@LotusAndMe
Copy link

LotusAndMe commented Aug 26, 2022

Get same problem, after reset form with useFormik.formReset() check box do reset in state, but dont re-rendered. Solution is just give property checked to your input:

<input type="checkbox" id="agreement" checked={formik.values.agreement} value={formik.values.agreement} onChange={formik.handleChange} onBlur={formik.handleBlur} />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants