Re: [WICG/webcomponents] Form-associated custom elements: being a submit button (#814)

@calebdwilliams I think the difference would lie with it being implicit registration as submit versus (`.submitButton = boolean`) vs explicit (`register`/`unregister`).

If it's a `boolean` it's contained in and of itself. The steps of implicit form submission will still find that element and check if it has that boolean set while it's running the traditional steps of walking the DOM tree. Attaching itself directly to the form (via the register/unregister functions) could change the steps required for finding the submit button during implicit submission. It implies there's a registration list that the form maintains. The form, internally would have to check if anything has attached itself as a submission (and it would probably be a list since there can be multiple), and then check each of them. Then it's a question of, does that occur before or after the DOM walking? 

An example:

```html
<form id=form>
  <input> <!-- Receives ENTER press -->
  <button type=submit>1</button>
  <x-submit>2</x-submit>
  <button type=submit>3</button>
<form>
<button type=submit for=form>4</button>
<x-submit for=form>5</x-submit>
````

Button 1 should take preference. If 1 is not available (disabled or removed) then 2. If not 2, then 3 (and so on). We don't want 4 to jump before 3, which could be the case if we bypass the DOM order steps.

------

Also, if a DOM is removed/moved, you have to unregister as well. And you need the form with which you were registered to keep proper logic symmetry (if there's a register, you assume an unregister). If you want to keep it implicit and "auto-unregister", then the form itself has to double check that the FACE is still associated with itself, or perform the unregister steps automatically. I feel like that's extra steps for the browser implementers. (And I guess maybe even yourself as a polyfill writer 😆 .)

----

There's also a lifecycle/state question. Is a FACE a submit button only if associated with a form? Can it just be a detached submit button? Can I register a button with a form manually? Can I use a detached form and register the submit before adding it to the DOM? Can a button be associated with one form, but the submit for another? If not, will it throw an error?

But I could be wrong of course, but as a component author, I don't see a problem with scripting my FACE submit buttons to flag themselves with a boolean, and scripting my FACE input fields to call the implicit submit function. In my logic, I would set a boolean as `true` if the `[type]` attribute is set to `"submit"` regardless if it's associated or not. 

---

As for part of HTMLFormElement or internal, it's a question of scope. Non-boundary crossing native elements (aka LightDOM) don't need to attach ever, AFAIK. They have the `[for]` attribute and should be using that. Maybe we'd be facilitating some implementation for design that don't easily set element IDs (frameworks), but they still technically have one option. Giving them two may be needlessly confusing.

---

PS: Love your polyfill work and use them all the time :) 

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/814#issuecomment-1446409967

You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/814/1446409967@github.com>

Received on Monday, 27 February 2023 14:22:46 UTC