You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A native Web Component that wraps a <form> element to handle submission, validation gating, loading state, and server-side error injection. Consumers slot in their own x-form-field, x-checkbox, and submit buttons.
Tag name
<x-form></x-form>
Observed attributes
Attribute
Type
Default
Description
loading
boolean
false
Prevents submit dispatch and sets aria-busy="true" on the shadow form
novalidate
boolean
false
Skips constraint validation before dispatching the submit event
autocomplete
string
"on"
Forwarded directly to the shadow <form> element ("on" | "off")
Boolean attributes follow standard HTML conventions: presence means true, absence means false.
Properties
Property
Type
Reflects attribute
loading
boolean
loading
novalidate
boolean
novalidate
autocomplete
string
autocomplete
Methods
Method
Signature
Description
submit()
() → void
Programmatically submits the form via requestSubmit() — triggers the full validation + event pipeline
reset()
() → void
Calls form.reset() on the shadow form — triggers formResetCallback on associated form-associated elements
setFieldError(name, msg)
(string, string|null) → void
Sets the error attribute on the first light-DOM element matching [name="…"]. Pass "" or null to clear.
clearErrors()
() → void
Removes the error attribute from all light-DOM elements that currently have it
Events
Event
Cancelable
Detail
When
x-form-submit
yes
{values: Object}
After validation passes (or novalidate), and not while loading is set
x-form-reset
no
{}
After the shadow form.reset() completes
x-form-submit detail
values is a plain JS object keyed by field name. Collection strategy:
Queries this.querySelectorAll("[name]:not([disabled])") in the light DOM.
Checkbox/radio elements (detected by type="checkbox", type="radio", or tagName === "x-checkbox") are only included when checked === true.
All other fields contribute field.value || "".
Slots
Slot
Description
(default)
Form fields, submit buttons, and any other content
x-form imposes no layout on slotted content. Use the --x-form-gap and --x-form-width CSS custom properties to control the flex column layout of the shadow <form>.
CSS custom properties
Property
Default
Description
--x-form-gap
1rem
gap between flex items in the shadow [part=root]
--x-form-width
100%
Width of the shadow <form>
Parts
Part
Element
root
The shadow <form> element
Use ::part(root) to style the inner form container directly.
The shadow <form> always has the novalidate HTML attribute so the browser does not show native constraint UI automatically. Validation is run manually via form.reportValidity() during the submit lifecycle, which still surfaces browser/ElementInternals validation UI on invalid fields.
Submit lifecycle
User clicks a type="submit" button inside the slot, or el.submit() is called.
requestSubmit() fires the native submit event on the shadow form.
The handler always calls event.preventDefault().
If loading is set → bail silently (no event dispatched).
If novalidate is not set → call form.reportValidity():
// After receiving a 422 response:form.setFieldError('email','An account with this email already exists.');form.setFieldError('password','Password does not meet requirements.');// Clear all errors (e.g. on reset):form.clearErrors();