-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does Formik not handle submit on enter? #1418
Comments
I was just solving a similar issue, I've included a visually hidden element in my forms. This is when the default submit button is not within , e.g. in a modal footer. Maybe that helps! |
|
You maybe hitting the known input autofill React bug. Here is the umbrella issue: facebook/react#11097 If you can provide a codesandbox we can then debug together |
Generally tho, you should not implement onKeyPress |
I ran into the same issue with a form in a dialog where the submit button was outside the form in the dialog footer. I fixed it the way @KidkArolis suggested with a hidden input. |
I had a similar problem. Issue was that in my custom const Input = ({ label, field, ...props }) => {
delete props.form;
return (
<div className="some-class-name">
<input {...field} {...props} />
</div>
);
}; or predefine all possible attributes manually |
I am not passing along the form prop into my custom input, I have a 😢 |
with no custom input, my form is working with pressing enter. what else could cause this? I have a custom on change as well, maybe something with the events? |
What version of formik do you use? |
1.5.8 |
I’ll post back when I figure it out. I started with the docs example in my form and am adding my customizations in one by one |
the answer to this particular issue is "yes it works" as long as
@kelly-tock if you think you've found a different bug which otherwise prevents formik's submission, feel free to open a separate issue and try to replicate in a code sandbox. @IanBarbour does this info help close out your issue? |
actually I have a textarea field/form, which does not work:
|
@schmitch I believe you have to do control+enter in order to get that working. Either way it's a bit different than this original issue which is whether the Formik component handles submit on Enter, while that refers to the specific field. Try asking your question in the Discord channel or opening a new issue with a CodeSandbox reproduction of your issue. |
Can you please let know how you did it. I am facing the same issue, where my submit is in my modal and pressing enter is not submitting the form |
I had a problem with axios when used with Formik. It did continuously sent duplicate requests. Then, I could find the problem while reading this issue. The problem came from the sumbit="button" that I used to send request with Formik. <Button
type="submit"
disabled={isSubmitting}
onClick={submitForm}
fullWidth
color="primary"
variant="contained"
> It is likely that when the type is set to "submit" it sends duplicate request. So, I removed type="button" from the code and used the code similar to this. <Button
type="submit"
disabled={isSubmitting}
onClick={submitForm}
fullWidth
color="primary"
variant="contained"
>
<input className="x-display" type="submit" /> and CSS .x-display {
display: none;
} It solved both problem of duplicate request and using enter to submit the form. First, I thought it was the proxy server problem that I was using but it was from the Formik. Hope, this helps others later. I had to spend many times until I find this issue. |
@KSVarun if you provide a sandbox repro I can take a look at it. If your |
I'm running into this issue on a project as well and none of the solutions in the thread work -- is this still waiting on an upstream fix for facebook/react#11097 ? |
@timstallmann submit on enter works. If that React bug is affecting you, you'll have to wait for that upstream, but generally enter triggers formik submit. If you provide a codesandbox repro it'll be easier to discuss the issue you're having. |
Make sure your input field is wrapped within |
I was running into this and got it fixed thanks to some tips in SO. The three things I found that affected this issue:
|
Yeah by hidden you'll definitely want to do something like the screen reader text class not only for reasons of Browser Compatibility, but so that screen readers will also understand there is a button that can be interacted with. |
You may be experiencing a similar issue to what I was, and I was able to solve it. My problem was that I had another button on the page that did not have a "type" defined. Therefore when pressing Enter the browser was finding the first button on the page, assumed it was the submit button because the type was not defined, and firing that instead. Make sure that all buttons on your page are defined as |
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 |
onClick={submitForm} this really helped |
Should I implement my own onKeyPress functionality or is there a way to handle this within the tools supplied in Formik?
Thanks!
The text was updated successfully, but these errors were encountered: