3

Is there a way to reset the form and set the state at the same go? I tried the below code and it does not seem to work. Any inputs are appreciated.

<Form
    onSubmit={this.onSubmit}
    render={({handleSubmit, form, submitting, pristine, values}) => (
        <form onSubmit={handleSubmit}>
.
.
.
.

<button
    type="button"
    onClick={() => {
        form.reset;
        this.setState({"reset": true});
    }}
    disabled={submitting || pristine}
>
    Reset
</button>
</form>
Deep
  • 31
  • 1
  • 2
  • 3
  • There's no reason why that should not be possible. If you could make a CodeSandbox demonstrating what you're trying to do, it would be a lot easier to help you. – Erik R. Mar 25 '20 at 09:11

2 Answers2

6
<button
  type="button"
  onClick={() => {
      form.reset();
      this.setState({"reset": true});
  }}
  disabled={submitting || pristine}
>
    Reset
</button>

I think what you missing is executing form.reset function

Khoi Nguyen
  • 61
  • 1
  • 2
0

You should call the reset method instead of having form.reset:

<button
  type="button"
  onClick={() => {
    form.reset(); <-------------
    this.setState({"reset": true});
  }}
  disabled={submitting || pristine}
>
  Reset
</button>
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360