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 form after form submission succeed

See original GitHub issue

Hi there ! I was wondering how i can reset my form on successful submit ? Seems that we don’t have access to the reset() function in onSubmit(). How can i handle that ? Thanks for the work by the way , react-final-form is awesome 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:50 (3 by maintainers)

github_iconTop GitHub Comments

26reactions
Aeon-Avinashcommented, May 22, 2019

Works perfectly with async/await

onSubmit={async event => {
              await handleSubmit(event)
              form.reset()
            }}

I tried various suggestions to reset the form on successful submission but to no avail. I was just about to give up on Final Form and move back to Formik.

But then I tried my luck with async/await and it works like a charm! Thanks Final Form 🥇

25reactions
michalmodrzejewskicommented, Jun 3, 2020

Final-form introduced new type in 4.20 version https://final-form.org/docs/final-form/types/FormApi

Quote from docs: “restart () => void Resets all form and field state. Same as calling reset() on the form and resetFieldState() for each field. Form should be just as it was when it was first created.”

Example code: const onSumbit = form => setTimeout(() => form.restart()) or with destructuring const onSumbit = { restart } => setTimeout(() => restart())

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Final Form reset form fields and validation but retain ...
The scenario is that I want to clear all the form fields on a successful submission but show a submit success message which...
Read more >
React Final Form - Reset After Submit - CodeSandbox
Demonstrates how to reset the form after submission. 1. 13.8k.
Read more >
How to reset a form after successful submit without including it ...
I have this scenario, after submitting the form I insert the response before the first child of the target element. I could achieve...
Read more >
Submit Form, Reset Form and Close Out Form upon success
Solved: I have an app where I have 5 screens. Using PATCH, on the Submit button, I am saving all 5 screen's data...
Read more >
React Final Form Reset Submit - StackBlitz
import {Form, Field} from 'react-final-form';. class App extends Component {. onSubmit = () => {. return new Promise(resolve => {.
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