react icon indicating copy to clipboard operation
react copied to clipboard

How to reset the form?

Open yadav-saurabh opened this issue 6 years ago • 2 comments

I am trying to reset the form after the form is submitted.

After the form is submitted the submit button gets disabled. How to reset the form and enable the submit button again for other submissions?

maybe something like below:


onSubmit={value => {
  var promise1 = new Promise(function(resolve, reject) {
    setTimeout(function() {
      resolve("foo");
    }, 300);
  });

  promise1.then(function(value) {
    // resetForm and enable submit 
    alert(value);
    // expected output: "foo"
  });
}}

yadav-saurabh avatar Nov 03 '19 15:11 yadav-saurabh

Typically we navigate to a different page or reinstantiate the form object. This should clear the submission settings. In the onsubmit you can change the submission object of the form to an empty object and that should also do it.

randallknutson avatar Nov 04 '19 15:11 randallknutson

I have the same issue. I need other submissions because I have BE validation errors. After the user fix invalid input values, we need to send the submission again I had already tried

  1. Update form submission
  2. Update form JSON by copying them
  3. Resetting form by using 'resetForm' event, after submission (and my requests) done Only one thing that helps me - reset the form after ~500ms. But it is a very bad solution

Is there any other way to set the form to its original "not submitted" state? Or make a form that always has "not submitted"" state

nikakoy131 avatar Sep 02 '21 12:09 nikakoy131

I am closing the issue as it was created too long ago and there are no new comments here. I hope it was resolved. If not, please reopen it. Thanks!

TanyaGashtold avatar Aug 31 '23 13:08 TanyaGashtold