- From: Carlos Lopez <notifications@github.com>
- Date: Fri, 24 Feb 2023 11:59:22 -0800
- To: WICG/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <WICG/webcomponents/issues/814/1444370901@github.com>
>Would just form.defaultSubmitButton be enough? Then form.defaultSubmitButton.click() is enough to submit it, right? Seems like yes according to https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#implicit-submission >A [form](https://html.spec.whatwg.org/multipage/forms.html#the-form-element) element's default button is the first [submit button](https://html.spec.whatwg.org/multipage/forms.html#concept-submit-button) in [tree order](https://dom.spec.whatwg.org/#concept-tree-order) whose [form owner](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-owner) is that [form](https://html.spec.whatwg.org/multipage/forms.html#the-form-element) element. ````js const { form } = this.elementInternals; const { defaultSubmitButton } = form; ```` >If the user agent supports letting the user submit a form implicitly (for example, on some platforms hitting the "enter" key while a text control is [focused](https://html.spec.whatwg.org/multipage/interaction.html#focused) implicitly submits the form), then doing so for a form, whose [default button](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#default-button) has [activation behavior](https://dom.spec.whatwg.org/#eventtarget-activation-behavior) and is not [disabled](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-disabled), must cause the user agent to [fire a click event](https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-click-event) at that [default button](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#default-button). ````js if (defaultSubmitButton) { if (!defaultSubmitButton.hasAttribute('disabled')) { defaultSubmitButton.click(); } return; } ```` >There are pages on the web that are only usable if there is a way to implicitly submit forms, so user agents are strongly encouraged to support this. >If the form has no [submit button](https://html.spec.whatwg.org/multipage/forms.html#concept-submit-button), then the implicit submission mechanism must do nothing if the form has more than one field that blocks implicit submission, and must [submit](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-form-submit) the [form](https://html.spec.whatwg.org/multipage/forms.html#the-form-element) element from the [form](https://html.spec.whatwg.org/multipage/forms.html#the-form-element) element itself otherwise. ````js if (getSubmissionBlockers(this.form).size > 1) return; // extraneous form.requestSubmit(); // not sure if form.submit() ```` That's how I'd implement it, given access to `defaultSubmitButton`. -- Reply to this email directly or view it on GitHub: https://github.com/WICG/webcomponents/issues/814#issuecomment-1444370901 You are receiving this because you are subscribed to this thread. Message ID: <WICG/webcomponents/issues/814/1444370901@github.com>
Received on Friday, 24 February 2023 19:59:35 UTC