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.

How to reset dirty or reinitialize form? dirty never false after call reset()

See original GitHub issue

Describe the bug Dirty is not reset after call reset().

To Reproduce Here is codesandbox for reproduce: https://codesandbox.io/embed/smoosh-shape-fuy5e

  1. There is SampleForm component to receive user and onSubmit props. it use useEffect() hook(line 15 ~ 18) for reset form when props.user is updated. but currently, I commented reset(user)(line 17) for reproduce.
  2. change some fields, and reset original value. the submit button’s disabled is toggle via formState.dirty (ex> Update name to Foo1, submit is enabled. Update name to Foo, submit is disabled)
  3. uncomment SampleForm line 17, reset(dirty) line. and try again step 2. the submit button is never disabled again even I tried set original value.

Expected behavior formState.dirty should be false when I change form value to original after call reset()

Screenshots App.tsx image

SampleForm.tsx: 2019-09-09 14-10-15 2019-09-09 14_11_13 (Ignore Rocket’s popup… 😉)

Desktop (please complete the following information):

  • OS: MacOS 10.14.16 mojave
  • Browser: Chrome
  • Version: 76.0.3809.132
  • react-hook-form@3.23.4

Additional context Maybe it is not a bug. but I want to reset dirty value after I call reset(). Is there another way to reset dirty? Thanks to your awesome library 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
bluebill1049commented, Sep 9, 2019

working on my end, if you can verify. we can release this fix soon 😃 ❤️

5reactions
iamchaniicommented, Sep 9, 2019

omg, blazing fast! I will check out your works!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Hook Form - Resetting "isDirty" without clearing form?
Kinda assumed isDirty would be cleared once the form was submitted, but it remains dirty. I can call reset from the onSubmit ,...
Read more >
useForm - reset - React Hook Form
DirtyFields and isDirty will remained, and only none dirty fields will be updated to the latest rest value. Check out the example.
Read more >
Input controls remain dirty and not pristine after form.reset() in ...
When calling form.reset() after changing a controls value, I would expect the controls to be reset to dirty: false, pristine: true, touched: false....
Read more >
Forms - Inertia.js
To reset the form values back to their default values, you can use the reset() method. Vue 2. Vue 3. React Svelte. //...
Read more >
Detect Unsaved Changes in Angular Forms | by Netanel Basal
When the beforeunload event emits, we check if the component is dirty. If it is, we set the returnValue to false, which will...
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