structyl

Form

stable

A form with declarative validation built on native ValidityState.

Basic usage

Examples

Login form

A complete login form with email, password, and validation messages.

Validation states

Form coordinates labels, controls and native ValidityState messages.

Features

  • Built-in and custom matchers.
  • Accessible error messages.

Installation

bash
pnpm dlx structyl add form

API Reference

Form.Root

The form element; tracks validity per field.

PropTypeDefault
onClearServerErrors() => void

Called on change to clear server-side errors.

Form.Field

Wraps a control with its label and messages.

PropTypeDefault
namestring

Field name — links label, control and messages.

serverInvalidboolean

Force-mark the field invalid from server validation.

Form.Label

Label bound to the field control.

PropTypeDefault
asChildboolean

Merge props onto the immediate child instead of rendering a default element.

false

Form.Control

The input. Reports native ValidityState.

PropTypeDefault
asChildboolean

Merge props onto the immediate child instead of rendering a default element.

false

Form.Message

A validation message, shown when its match fails.

PropTypeDefault
matchValidityMatcher | function

A built-in matcher (e.g. 'valueMissing') or a custom predicate.

forceMatchboolean

Always render the message.

Form.Submit

A submit button.

PropTypeDefault
asChildboolean

Merge props onto the immediate child instead of rendering a default element.

false
Form | structyl