Skip to content

Reset algorithm doesn't work in form-associated custom elements #10927

Open
@dSalieri

Description

@dSalieri

What is the issue with the HTML Standard?

There are 3 places in the specification where the reset algorithm is triggered:

  1. The reset algorithm, which resets the state of all form participants to default values

    1. If reset is true, then invoke the reset algorithm of each resettable element whose form owner is form.
  2. The create an element for a token algorithm, whose task is to create an element for the HTML parser.

    1. If element is a resettable element, invoke its reset algorithm. (This initializes the element's value and checkedness based on the element's attributes.)
  3. The reactivate algorithm, which is used to update the document

    1. For each formControl of form controls in document with an autofill field name of "off", invoke the reset algorithm for formControl.

The first case works fine, no questions about it, no matter whether via a button or via the reset() API, it works well and the formResetCallback hook makes itself known.

The second case fails, it does not call the formResetCallback hook (detailed below).

The third case also does not execute the formResetCallback hook, the conditions for its execution are unachievable (due with form-associated custom elements).


As a small test, I made this example for the create an element for a token case:

<script>
customElements.define("my-input", class extends HTMLElement {
  static formAssociated = true;
  connectedCallback() {
     console.log("my-input connected");
  }
  formResetCallback() {
     console.log("my-input performed formResetCallback");
  }
});
</script>
<form>
  <my-input></my-input>
</form>

And if you run such html file with a custom element that has the reset algorithm:

The reset algorithm for form-associated custom elements is to enqueue a custom element callback reaction with the element, callback name "formResetCallback", and an empty argument list.

Then we will not see the called formResetCallback hook, but this should work (yes, we are talking about the second case, when the HTML parser creates an element for the token and after run reset algorithm in step 13).

I checked this in the latest Chrome and Firefox, the hook is not called. What's wrong?


Maybe problem is in this note, why implementations don't correspond the step 13:

A custom element possesses the ability to respond to certain occurrences by running author code:

By the way, that wpt test is too old, it does not check what I am talking about.


What do you say editors?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions