Skip to content

Instantly share code, notes, and snippets.

@deebloo
Last active January 24, 2025 15:38
Show Gist options
  • Save deebloo/12dc5e326237a06912254bc7c25b7705 to your computer and use it in GitHub Desktop.
Save deebloo/12dc5e326237a06912254bc7c25b7705 to your computer and use it in GitHub Desktop.

Minimum integration for custom form inputs

  • Allow value to be set via an attribute
  • Do not reflect that value back to an attribute if set via a property
  • If a text input. Listen for keyboard events. If enter key is called the form should be submitted.
  • DO NOT just call form.submit since this will not fire the submit event. Instead create a submit button, append it to the form. click the button and then remove it
    • const btn = document.createElement("button");
      btn.type = "submit";
      form.append(btn);
      
      btn.click();
      btn.remove();  
  • Should participate in form submission
    • static formAssociated = true;
    • #internals = this.attachInternals();
    • this.#internals.setFormValue(value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment