Reset form after form submission succeed
See original GitHub issueHi 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:
- Created 6 years ago
- Comments:50 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Works perfectly with async/await
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 🥇
Final-form
introduced new type in4.20 version
https://final-form.org/docs/final-form/types/FormApiQuote 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 destructuringconst onSumbit = { restart } => setTimeout(() => restart())