formik
formik copied to clipboard
Please make onSubmit/handleSubmit optional for use cases that don't involve submitting forms
🚀 Feature request
Current Behavior
The Formik
component's onSubmit
prop is required. Failing to use it causes a runtime error when submitting and a TypeScript error (if you use it). You can work around this by passing a no-op function (onSubmit={() => {}}
), but I think it's misleading for beginners and makes it seem like you need some specific code inside onSubmit
.
Desired Behavior
Formik
should allow the onSubmit
prop to be omitted. Similarly, withFormik
's handleSubmit
option should be optional.
Suggested Solution
Make the type optional in TypeScript (using undefined
or ?:
in the prop type) and disable any submitting functionality when onSubmit
is not given. Any validation and other synthetic events that don't rely on submitting should still work.
Who does this impact? Who is this for?
Any form state management use case that doesn't involve submitting forms, for example:
- Beginners learning how to use Formik without a server
- Experienced users creating a prototype of an app that doesn't have a server implemented yet
- Calculating results based on form fields immediately as the user changes/blurs fields (I have multiple calculator apps that do this, and it's my main use case for this feature)
- Persisting a bunch of fields to local storage without having to manage form state manually
Describe alternatives you've considered
There could be another library for managing state of form fields that aren't for submitting, but personally I think Formik is good enough at that already (despite this issue) that it wouldn't be worth the effort.
Additional context
When I first learned about Formik, I avoided it because I saw the onSubmit
prop and assumed I had to have some sort of REST/GRAPHQL server/service in order to use it. I didn't realize until later that I could just use it for local state management. I think making submit behavior optional would make it easier to learn and understand the purpose of Formik. For me the biggest advantage of Formik is managing form state, not submitting forms.
I'd be happy to try a pull request if there's interest in merging it, otherwise I might just maintain a fork.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days
This is still an issue and the associated pull request is still active
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days
This is still an issue and the associated pull request is still active
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days
This is still an issue and the associated pull request is still active
please fix this issue !
I would also like to see onSubmit being optional rather than required. In my particular case, I only need the state statement feature of Formik rather than handling submitting form.
Agreed!
Was just wondering why I have to use Formik's onSubmit function when I have my own. Please fix!
+1
+1
+1
+1
Please thumbs up and optionally subscribe to my thread if you want to support it without commenting on anything specific.
Also, would the maintainers be interested in PRs for this?
+1
good
I want to maintain form state management and flexibility while avoiding form submissions. This feature would be beneficial. 👍
Is the PR still active or stale ?
I'm not aware of a PR, and I didn't want to start one without confirmation that a maintainer would review it. Additionally the repository hasn't merged an external feature PR in 6 months.
I'm not aware of a PR, and I didn't want to start one without confirmation that a maintainer would review it. Additionally the repository hasn't merged an external feature PR in 6 months.
I see