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.

Reset one field resetting the whole form

See original GitHub issue

Hello,

Describe the bug My understanding is reset can be used to reset one field only (while keeping other dirty ones as they are)

Simple scenario: 2 drop downs (state & city). I want to reset the city when the state changes

To Reproduce Steps to reproduce the behavior:

  1. Go to codesandbox
  2. Select state/city works fine
  3. Now uncomment React.useEffect
  4. Now try to select a state (nothing will be selected cause the reset is resetting the whole form)

Codesandbox link (Required) https://codesandbox.io/s/keen-monad-ddoyc?file=/src/App.tsx:524-621

Expected behavior reset to only reset the field(s) provided to it

Screenshots

https://user-images.githubusercontent.com/13101565/118499582-456df480-b751-11eb-8ef3-959706228473.mov

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
JGibelcommented, May 17, 2021

csb w/ setValue in case anyone from the internet comes across this in the future: https://codesandbox.io/s/crazy-gates-lkuk8

1reaction
mwmcodecommented, May 17, 2021

I ended up using setValue instead. Please close if it’s not an issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reset only specific fields of form in angular 5
It works perfectly fine resetting the whole form, but is it possible to just reset some of the elements and keeping other the...
Read more >
Reset form - only the specific fields - Power Platform Community
Solved: Hi Experts, I have to reset the form after submitting the form, but not to reset one particular field. Example: I am...
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 >
HTML DOM Form reset() Method - W3Schools
The reset() method resets the values of all elements in a form (same as clicking the Reset button). Tip: Use the submit() method...
Read more >
How to reset or clear a form using JavaScript? - Tutorialspoint
By using the reset method with the variable (which contains the return value of the call to the method) we can reset every...
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