--- url: "https://web.dev/articles/more-capable-form-controls" titulek: "More capable form controls | Articles | web.dev" h1: "More capable form controls Stay organized with collections Save and categorize content based on your preferences." popis: "Build custom elements that work like built-in form controls." jazyk: "en" kanonicka: "https://web.dev/articles/more-capable-form-controls" drobecky: ["Articles", "More capable form controls"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-13 23:13:37" znaku: 12473 slov: 1857 kodovani: "iso-8859-2" sha256: "6fa4cf7a289a3dafaa3ad4257eb523e3946bd26d33d2b63746c0ea22fd04335a" --- More capable form controls Stay organized with collections Save and categorize content based on your preferences. Arthur Evans Published: August 8, 2019 Many developers build custom form controls, either to provide controls that aren't built in to the browser, or to customize the look and feel beyond what's possible with the built-in form controls. However, it can be difficult to replicate the features of built-in HTML form controls. Consider some of the features an `` element gets automatically when you add it to a form: The input is automatically added to the form's list of controls. The input's value is automatically submitted with the form. The input participates in [form validation](/learn/forms/validation). You can style the input using the `:valid` and `:invalid` pseudo-classes. The input is notified when the form is reset, when the form is reloaded, or when the browser tries to autofill form entries. Custom form controls typically have few of these features. Developers can work around some of the limitations in JavaScript, like adding a hidden `` to a form to participate in form submission. But other features just can't be replicated in JavaScript alone. Two web features make it easier to build custom form controls, and remove the limitations of custom controls: The `formdata` event lets an arbitrary JavaScript object participate in form submission, so you can add form data without using a hidden ``. The form-associated custom elements API lets custom elements act more like built-in form controls. These two features can be used to create new kinds of controls that work better. Event-based API Browser Support 5 12 4 5 [Source](https://developer.mozilla.org/docs/Web/API/FormData) The `formdata` event is a low-level API that lets any JavaScript code participate in form submission. Add a `formdata` event listener to the form you want to interact with. When a user clicks submit, the form fires a `formdata` event, which includes a [`FormData`](https://developer.mozilla.org/docs/Web/API/FormData) object that holds all of the data being submitted. Each `formdata` listener gets a chance to add to or modify the data before the form is submitted. Here's an example of sending a single value in a `formdata` event listener: `const form = document.querySelector('form'); // FormData event is sent on
submission, before transmission. // The event has a formData property form.addEventListener('formdata', ({formData}) => { // https://developer.mozilla.org/docs/Web/API/FormData formData.append('my-input', myInputValue); });` Form-associated custom elements You can use the event-based API with any kind of component, but it only lets you to interact with the submission process. Standardized form controls participate in many parts of the form lifecycle. Form-associated [custom elements](/articles/custom-elements-v1) aim to bridge the gap between custom widgets and built-in controls. Form-associated custom elements match many of the features of standardized form elements: When you place a form-associated custom element inside a ``, it's automatically associated with the form, like a browser-provided control. The element can be labeled using a `