Re: [w3c/webcomponents] Need callback for form submit data (#187)

First let met say that all of these things seem like they can be done on top of the current FACE (form-associated custom elements) pull request. That's a good sign :).

So I think there are two issues with implicit submission:

1. Letting implicit submission work on a FACE, so that when you press Enter while focusing that FACE, it submits the form.
2. Letting implicit submission click a FACE submit button, so that when you press Enter while focusing a normal input type=text, it clicks your FACE submit button.

> With whatwg/html#4187, manual implicit submission code would be:

This is about (1), from what I can tell.

I think `form.requestSubmit(control)` should probably be `control.click()` to perfectly imitate the spec. ("must cause the user agent to fire a click event at that default button.")

But I also wonder, it seems like you'd need to add code like that to an keydown (keypress? keyup?) handler, and filter for the Enter key, right? That seems a bit fragile since it's assuming the Enter key is correct, but that's just prevailing convention... Maybe the missing piece is some kind of "requestimplicitsubmit" event, which gets fired on the Enter key or similar? Or a custom element callback??

I also think there's room for making this easier by adding a `HTMLFormElement.prototype.defaultButton` which would let you skip the loop.

In general I like the idea of people adding this manually, but doing it using platform-provided primitives that make it intuitive. So with all of my above it might be something like

```js
this.addEventListener("requestimplicitsubmit", () => {
  const button = this.#internals.form.defaultButton;
  if (!button.disabled) {
    button.click();
  }
});
```

To reiterate, I am happy with these pieces being done after the initial version of FACE.

> :default

This seems to start discussing (2). In particular I think `this.#internals.submitButton = true` should cause (2) to start working.

I also wonder about how this relates to https://github.com/w3c/webcomponents/issues/738#issuecomment-484829591 about allowing you to manually toggle states like `:checked`. (Did we open a dedicated issue for that, separate from `:state()`?) In particular, should we allow you to manually toggle `:default`? That seems necessary to get some of its other behaviors, like for `<option selected>` and `<input type=checkbox checked>`. But manual toggling seems in conflict with deriving it from `internals.submitButton`.

I've honestly never seen anyone use `:default` before your code example today so I am not sure how high priority this is. And especially unsure how high priority it is to support it for the non-button cases. But it's worth thinking about.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/187#issuecomment-490105380

Received on Tuesday, 7 May 2019 14:33:00 UTC