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.

Unexpected `onFirstChange` behavior with regard to `Form.reset()`

See original GitHub issue

Environment

  • OS: macOS High Sierra 10.13.6
  • Node: 10.10
  • NPM: 6.4.1
  • react-advanaced-form: 1.6.7

What

Current behavior

  • Provide a Form component with an onFirstChange callback.
  • Change a field in the form.
  • The callback passed to onFirstChange is invoked.
  • Call the form’s reset() method.
  • Change a field in the form again.
  • The callback passed to onFirstChange is not invoked.

Expected behavior

I would personally expect a form that has been reset to no longer be dirty.

My use case is a user profile form. It is only submittable when the form is dirty. After it is successfully submitted and updated via the server I call Form.setValues() and Form.reset(). Currently I can’t figure out a way to track its dirty state after past point.

Why

The only place the Form’s dirty state property is ever set to false is in the constructor. https://github.com/kettanaito/react-advanced-form/blob/master/src/components/Form.jsx

It seems like either a design decision or an oversight. If it’s intentional I’m just looking for a way to handle my use case. Otherwise I’m happy to submit a PR to update this behavior.

How

Here is a CodeSandbox demo: https://codesandbox.io/s/k54v4r9mvo

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kylepixelcommented, Mar 15, 2019

Thanks for the quick response!

I’ll open a PR today for the fix to reset().

And your response regarding initialValues makes sense. Your proposed solution will work for me.

0reactions
kettanaitocommented, Mar 15, 2019

Fixed in #373. Will be published in the next patch version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected reset behavior · Issue #1752 · react-hook-form ...
This is expected behavior for Controller , please give the input a value eg: '' instead of undefined. for native input, we are...
Read more >
Weird form reset event behavior - javascript - Stack Overflow
The reset event is called before anything is reset rather than after, to give you a chance to cancel the reset if you...
Read more >
HTMLFormElement.reset() - Web APIs | MDN
The HTMLFormElement.reset() method restores a form element's default values. This method does the same thing as clicking the form's control.
Read more >
Form reset after clicking a button? - Salesforce Stack Exchange
I believe this.form.reset is in fact resetting your form, but the trouble is, when the "Quote List" button is pressed, ...
Read more >
HTML DOM Form reset() Method - W3Schools
Definition and Usage. The reset() method resets the values of all elements in a form (same as clicking the Reset button). Tip: Use...
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