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.

form is not resetting its value

See original GitHub issue

my submit function

   submit = (values) => {
      return axios
         .post('shops', values)
         .then((res) => {
            alert.success('Shop Created.'); // on success, its showing
            this.refs.newShopForm.reset(); // but this is not setting forms value
         })
         .catch((err) => {
            this.refs.newShopForm.updateInputsWithError(err.response.data); // on error, its showing errors
         });
   };

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:17

github_iconTop GitHub Comments

1reaction
C3PablOcommented, Apr 5, 2017

I had the same problem but just with textarea fields. I have a formsy-react wrapper for my input components so I can use them with o without formsy-react. Calling reset was cleaning the values as expected but passing undefined as a value to the children component didn’t updated it so I end up passing value={this.getValue() || ''} and that solved the issue

1reaction
hschoenburgcommented, Oct 19, 2016

Cannot for the life of me get the from to reset its inputs. Trying:

this.refs.form.reset();

Tried passing value={this.state.something} and then calling this.setState({value: ‘’}) on submit. That didn’t work either.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Form resetting is not working - Stack Overflow
If your objective is only to reset the form, you could try this: <input type="reset" id="reset" value="Reset" onclick="this.form.reset();"/>.
Read more >
ReserForm() not resetting all values on the form
Solved: Hello Experts , i am writing reset form on my form submission button but it does not reset value for some of...
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 <input ...
Read more >
Using JavaScript to reset or clear a form
These methods are very convenient to use, but they do not provide the functionality of clearing all the fields, including their default values....
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 >

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