Skip to content

Disable submission on enter #3235

Answered by johnrom
antarikshray asked this question in Q&A
Discussion options

You must be logged in to vote

NOTE! This is questionable at best for accessibility. Some users traverse forms with only the keyboard, so you should confirm this works with only the keyboard.

This is an event which React gets from HTML. HTML forms naturally submit when the user presses enter anytime there is a submit button. You can either remove the "<button type="submit" /> and replace it with a non-submit button which triggers formik.handleSubmit(event) on click, or follow any of the other recommendations on various StackOverflow issues.

One Formik-specific example would be to replace Formik's <Form /> helper component with a regular form, and replace its onSubmit:

const MyForm = () => {
  return <Formik {...formi…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by antarikshray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants