Form - Enter key to submit form - JavaScript react-final-form

Are you submitting a bug report or a feature request?

Bug report

What is the current behavior?

Upon hitting submit button, the form is not submitted when hitting Enter key

What is the expected behavior?

The form should be submitted upon hitting 'Enter key'. Sample code:

What's your environment?

"react-final-form": "^6.0.1", Chrome Node: 10.15.3

Sample code sandbox: https://codesandbox.io/s/9ywq085k9w

Asked Oct 10 '21 10:10
avatar acejusto11
acejusto11

7 Answer:

I'm seeing that it does submit upon hitting "enter." Where are you seing the problem?

1
Answered Oct 11 '19 at 14:54
avatar  of tstirrat15
tstirrat15

@tstirrat15 I have the same. Is it not a bug? As I understand it is en expected behaviour. Can we disable that?

1
Answered Feb 27 '20 at 20:02
avatar  of il421
il421

@il421 I'm a bit confused. What behavior do you want and what behavior do you see?

I was saying that in the bug report submitted above, they were complaining that the form wasn't submitted when they pressed Enter, but when I went to their sandbox, entered things into the form, and pressed Enter, the form submitted (as I would expect from the way that form is constructed).

1
Answered Feb 27 '20 at 21:22
avatar  of tstirrat15
tstirrat15

You can wrap your form with

<form onSubmit={handleSubmit}>
....
</form>

it will then perform the native browser behavior for forms, which is Submit on Enter key.

1
Answered May 04 '20 at 19:37
avatar  of idangozlan
idangozlan

You can wrap your form with

<form onSubmit={handleSubmit}>
....
</form>

it will then perform the native browser behavior for forms, which is Submit on Enter key.

My form wasn't submitting on Enter with this alone. I also had to add a <button> with type="submit" to the form then it started working.

edit: For anyone else that has their submit button outside their form you can still make Enter work by adding a submit button to the form and setting its style to display: none

1
Answered Sep 06 '20 at 12:10
avatar  of joshraker
joshraker

edit: For anyone else that has their submit button outside their form you can still make Enter work by adding a submit button to the form and setting its style to display: none

A better approach for modern browsers is to use the attribute "form" on the submit button:

https://stackoverflow.com/questions/7020659/submit-form-using-a-button-outside-the-form-tag/12567605#12567605

1
Answered Jan 21 '21 at 06:57
avatar  of alfondotnet
alfondotnet

Just add html form inside Form:

<Form>
{ 
({handleSubmit}) => 
<form onSubmit={handleSubmit}>
//some fields... 
<button type='submit'>Submit form</button>
</form>
}
</Form>
1
Answered Apr 23 '21 at 10:21
avatar  of RewriteH
RewriteH