Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forms mishandle submit for Enter key #2093

Closed
tmcwilliam opened this issue Aug 26, 2014 · 8 comments

Comments

Projects
None yet
6 participants
@tmcwilliam
Copy link

commented Aug 26, 2014

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/

@sophiebits

This comment has been minimized.

Copy link
Collaborator

commented Aug 26, 2014

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

@sophiebits sophiebits closed this Aug 26, 2014

@kyeotic

This comment has been minimized.

Copy link

commented Jun 4, 2015

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

@browniefed

This comment has been minimized.

Copy link

commented Jun 4, 2015

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

@kyeotic

This comment has been minimized.

Copy link

commented Jun 4, 2015

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>

@browniefed

This comment has been minimized.

Copy link

commented Jun 4, 2015

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

@hugotox

This comment has been minimized.

Copy link

commented Sep 12, 2015

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

@sophiebits

This comment has been minimized.

Copy link
Collaborator

commented Sep 12, 2015

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

@naoisegolden

This comment has been minimized.

Copy link

commented Jul 19, 2016

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.