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
7 Answer:
I'm seeing that it does submit upon hitting "enter." Where are you seing the problem?
@tstirrat15 I have the same. Is it not a bug? As I understand it is en expected behaviour. Can we disable that?
@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).
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.
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
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:
Just add html form inside Form:
<Form>
{
({handleSubmit}) =>
<form onSubmit={handleSubmit}>
//some fields...
<button type='submit'>Submit form</button>
</form>
}
</Form>
Read next
- Support 'transparent' as a acceptable color. - Java react-native-bootsplash
- /var/lib/dpkg/info/vernemq.postinst: line 11: syntax error near unexpected token `else' - Erlang vernemq
- Difference in puppet-lint behavior between `pdk validate` and `rake lint` - Ruby pdk
- http-ui only binds to localhost (127.0.0.1) - bettercap
- tdesktop Bug with opening context menu in KDE system tray - Cplusplus
- MyAccount :: Order Details :: Order Details by Order Number - PHP magento2
- .collect-file pollution in /tmp - Groovy nextflow
- openpose bash: scripts/osx/install_deps.sh: No such file or directory - Cplusplus