react icon indicating copy to clipboard operation
react copied to clipboard

Forms mishandle submit for Enter key

Open tmcwilliam opened this issue 12 years ago • 8 comments

React seems to be executing the first event handler attached to elements in a form rather than executing the onSubmit handler when hitting the Enter key.

jsFiddle: http://jsfiddle.net/tmcwilliam/mufcw3wv/

tmcwilliam avatar Aug 26 '14 19:08 tmcwilliam

Little-known fact: the <button> tag defaults to type="submit". If you change it to type="button", your fiddle works as intended.

sophiebits avatar Aug 26 '14 21:08 sophiebits

@spicyj That seems completely backwards. Is there a way to change that behavior?

kyeotic avatar Jun 04 '15 03:06 kyeotic

@tyrsius you could create a default React button component that has type="button" always on it.

browniefed avatar Jun 04 '15 04:06 browniefed

Is there a way to actually override <button>, or are you talking about making <other-button>? Because the latter isn't really changing the backwards behavior of <button>

kyeotic avatar Jun 04 '15 05:06 kyeotic

I'm recommending the <other-button> approach. React is focused on matching browser behavior, not modifying it regardless of how backwards it is.

browniefed avatar Jun 04 '15 06:06 browniefed

I'm curious why this issue was closed? Seems a legit issue

hugotox avatar Sep 12 '15 00:09 hugotox

This is part of how HTML works, not specific to React at all.

sophiebits avatar Sep 12 '15 00:09 sophiebits

@hugotox:

If a button is not set to type="button" it will default to be of type="submit", making it so that you have more than one submit button. Pressing enter will run the first one defined.

naoisegolden avatar Jul 19 '16 15:07 naoisegolden