A custom element inside a form does not contribute data to submission by default. Set `static formAssociated = true` on its class to opt in, then use `ElementInternals` to provide the value the form should submit. section 3.9
A radio group in a form
A `<radio-group name="primaryColor" values="red,green,blue">` can sit beside Submit and Reset buttons. Its `name` supplies the form-data key; its selected color supplies the value. section 3.10 section 3.9
For a vanilla custom element:
- Declare `static formAssociated = true` on the class, not in its constructor or an instance method. Obtain internals with `this.attachInternals()`. section 3.9
- Call `internals.setFormValue(value)` for the initial value and whenever it changes. Pass a `FormData` object instead to submit multiple named values. section 3.9
- For reset behavior, save the initial value in `formAssociatedCallback()` and restore it in `formResetCallback()`. section 3.10
With Stencil, set `formAssociated: true` in `@Component` and obtain internals through `@AttachInternals()`. Call `setFormValue` during `componentWillLoad` and after value changes. A single submitted value uses the element’s `name` as its key; with `FormData`, the component must choose the keys. section 6.12 section 3.9
Listing 3.14 radio-group example
<form action="https://httpbin.org/post" method="post"> #1
<radio-group
legend="Primary Color"
labels="Red,Green,Blue"
name="primaryColor"
value="red"
values="red,green,blue"
>
<div slot="before">Choose a primary color.</div> #2
<div slot="after">This will be the most used color.</div> #3
</radio-group>
<div>
<button type="submit">Submit</button>
<button type="reset">Reset</button>
</div>
</form>
The complete form markup shows the radio group’s `name` and initial `value` alongside submit and reset controls. section 3.10
