react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

Form - Enter key to submit form

Open acejusto11 opened this issue 7 years ago • 7 comments

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:

{ return (

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

tstirrat15 avatar Oct 11 '19 14:10 tstirrat15

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

il421 avatar Feb 27 '20 20:02 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).

tstirrat15 avatar Feb 27 '20 21:02 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.

idangozlan avatar May 04 '20 19:05 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

joshraker avatar Sep 06 '20 12:09 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

alfondotnet avatar Jan 21 '21 06:01 alfondotnet

Just add html form inside Form:

<Form>
{ 
({handleSubmit}) => 
<form onSubmit={handleSubmit}>
//some fields... 
<button type='submit'>Submit form</button>
</form>
}
</Form>

excal1bu7 avatar Apr 23 '21 10:04 excal1bu7