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.

Way to disable the submit event triggered by pressing the enter key while focusing an input field

See original GitHub issue

Hi folks, let’s say I have a Formsy-React Form and when the use typing down the characters, the submit event can be triggered by pressing the <kbd>Enter</kbd> button.

Is there a way to disable this functionality?

I understand this is a feature for form element(Trigger by pressing the <kbd>Enter</kbd> button). And I don’t want to bind events to each input fields, that doesn’t make sense, especially when you have lots of inputs and other elements.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

49reactions
Semigradskycommented, Jul 5, 2016
...
onKeyPress(event) {
    if (event.which === 13 /* Enter */) {
      event.preventDefault();
    }
},
render() {
  return (
      <Form onKeyPress={this.onKeyPress} ...
...
14reactions
shahrajatcommented, Oct 8, 2017

@Semigradsky Nice suggestion. It also requires extra caution when you have text-area element in the form. Can be fixed with:

if (event.target.type != 'textarea' && event.which === 13 /* Enter */) {
      event.preventDefault();
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevent users from submitting a form by hitting Enter
This method is unideal because it prevents the user from submitting the form by pressing enter while focused on the submit button. The...
Read more >
How to disable form submit on enter button using jQuery
There are two methods to submit a form,. Using the “enter” key: When the user press the “enter” key from the keyboard then...
Read more >
The Enter Key should Submit Forms, Stop Suppressing it
Basically, if the user hits enter when a text field is focused, the browser should find the first submit button in the form...
Read more >
React disable submit event triggered by pressing enter key
Sometimes I want to disable the submit event triggered by pressing the enter key while focusing an input field.
Read more >
ARIA: button role - Accessibility - MDN Web Docs
The button role is for clickable elements that trigger a response when ... give the text field focus to enable entering and additional...
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