Skip to content

setupFormSubmitter()

ts
function setupFormSubmitter(ctor: FormSubmitterConstructor): void;

Sets up a form submitter to handle form submission events.

This function adds an event listener to the submitter that handles click events, processes the form submission, and sets the submitter value in the form internals.

Borrowed from Material Web.

Parameters

ctor

FormSubmitterConstructor

The constructor of the form submitter element.

Returns

void

Example

Form aware custom button element.

ts
@customElement('form-button')
export class Button extends LitElement {
  // make the element form aware
  static readonly formAssociated = true;

  // a static initialization block that executes when the class is
  // first loaded, rather than when instances are created (an ES2022
  // feature, but the Typescript compiler will handle that)
  static {
    setupFormSubmitter(Button);
  }

  // the element internals, which is required for form association
  readonly internals = this.attachInternals() as unknown as ElementInternals;

  // ...
}