-
Notifications
You must be signed in to change notification settings - Fork 904
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
Pressing enter in a text field does not submit form #4182
Comments
The button submission will be fixed in an upcoming PR. Do native input text field submit forms on enter keypress? What happens if there are multiple? |
@asyncLiz Yes, native input submits form when you press enter. Event if there are multiple. Please, keep native behaviour. |
I've created a demo for submit and reset events. Submit buttons now work. |
@Totati I've tested your demo in Firefox and Chrome, it does work on Chrome but does not work on Firefox |
You are right. |
Updating issue title since it works on chrome |
I believe what you're experiencing is a browser quirk when handling forms. Specifically, the Enter key will only submit when either:
As the Material buttons do not inherit from the HTMLButtonElement it's likely that browsers do not apply the above rules to them. |
This is not true -> https://stackblitz.com/edit/js-raarmc Both in Chromium and Firefox the form gets submitted
Yes, this is true, and they try to come around this by creating a submit button |
You added a button (type is submit by default) 😛 |
I see, I misunderstand you. A form with a single focused input can be submitted with enter even when there's no submit button. (Didn't know that!) Adding more inputs and the form won't submit anymore. Will alert
Won't alert
Will alert
I have updated my demo for the reset and submit event. |
further investigation here. Seems that the form does submit. It seems in FF the form.submitter value is not being set correctly. Since this issue is solved closing. For submitter issues please see #4949 |
@e111077 The form does not submit for text-field in Chrome nor in FF. 🤷♂️ Could you provide an example where it works please? I'm interested what did I wrong in my reproduction. |
sorry for the hasty close |
Updated the title. Text fields do add their data to submitting forms, but pressing the enter key in a text field will not automatically submit its form right now. You'll need to add |
Also just in case it's relevant, a button in a <form id="frm">
<md-outlined-text-field autofocus class="txt-question w-100" name="q" data-loc-attr="label" data-loc-label="EnterQuestion">
<md-icon slot="leading-icon">help</md-icon>
<md-icon-button slot="trailing-icon">
<md-icon>search</md-icon>
</md-icon-button>
</md-outlined-text-field>
<input value="Normal input" />
<button>
Submit
</button>
</form> So the only problem now is to submit the form on pressing Enter on Material Text field. |
I don't think I agree from an a11y perspective. Icon buttons contained within a text field should have functionality tied to the text field itself, such as a clear button or a password visibility toggle. It may be unexpected to have a form submit when using the enter key to trigger the icon button. |
@asyncLiz that's a good point, thanks. I will fix my app by switching it to a separate button. Still pressing Enter in the textfield should trigger the form submit. Currently I have to manually handle the textfield's |
Have the bug fixed? It still cannot work on the latest Chrome. |
Not yet, the issue is still open |
Hi! I've built a small form example:
But it does not submit in any of the following cases:
Submit
buttonI understand it's an issue related to shadow dom, but, is there a way to make this work as expected?
The text was updated successfully, but these errors were encountered: