Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

form-field

Accessible form field web component with label, input, validation timing, custom error messages, and error summaries. Progressive enhancement from CSS-only validation to full JS coordination.

Attributes

Attribute Values Default Description
data-type checkbox, radio - Inline label + control layout. No validation icon (the control shows its own state).
data-no-icon boolean - Disable validation status icons
data-floating-label boolean - Label starts inside the input and floats above on focus or value. A real placeholder keeps the label floated. See data-floating-label.
data-valid boolean - Valid state (set by the component when a valid field has a value; can be set by hand)
data-invalid boolean - Invalid state: reveals the error output and icon (set by the component; can be set by hand)
data-pending boolean - Dims the field and blocks pointer input while something is in flight
data-state validating - Async-check hook: warning border and a spinner in the icon slot
data-message-invalid string Please check this field. Last-resort error message when neither a data-message-*, the authored error text nor the control supplies one (custom elements without a public validationMessage)
data-label-* string - Localize generated text: show-password, hide-password, digit (Digit {n} of {total}), incomplete (Enter all {total} digits), plus the strength meter labels

Input Attributes (for JS enhancements)

Attribute Values Default Description
data-type (on input) otp, pin - Enable OTP/PIN multi-box enhancement
data-length (on input) 4, 6, 8 6 Number of digits for OTP/PIN input
data-strength, data-rules (on password input) boolean; length:N,uppercase,lowercase,number,special length:8 Strength meter + rules checklist. See data-strength.
data-count (on textarea) "", words - Character/word counter, linked with aria-describedby. See data-count.
data-message-* (on input) string - Custom error message per ValidityState key (see JS-Enhanced Validation)

Element Structure

The form-field element groups a label, input control, and optional validation message.

Child Element Purpose Key Attributes
<label> Accessible field label for (matches input id)
<input> / <textarea> / <select> Form control (or a form-associated custom element, see Custom controls) id, name, validation attrs, data-message-*
<output class="hint"> Help text, collapses once the field is valid for
<output class="error"> Error message, hidden until invalid. Authored text is the no-JS message and the JS fallback. for, aria-live="polite"

ARIA wiring

When it upgrades, <form-field> wires the control for you:

  • aria-describedby lists the hint output(s) and the textarea counter, then the error output only while the field is invalid. Ids you already put in aria-describedby are kept (first); outputs without an id get one.
  • aria-invalid="true" mirrors the invalid state. For a radio group it goes on the field's radios; for OTP on the digit group; for custom elements on their inner combobox/group/input.
  • The collapsed error output is visibility: hidden, so it is not in the accessibility tree and a valid field never announces a stale error.
  • aria-errormessage is not used: screen-reader support is still too uneven.

Writing aria-describedby by hand is still fine (and is what the no-JS page uses).

Input Types

Works with all standard form controls: text, email, password, textarea, and select.

Password Toggle

Password inputs are automatically enhanced with a show/hide toggle button when JavaScript is available. No extra markup needed.

  • Appears automatically when JavaScript loads
  • Uses aria-pressed and aria-label for accessibility; localize the label with data-label-show-password / data-label-hide-password on the <form-field>
  • Positions adjust alongside validation icons
  • Add data-strength (and optionally data-rules) to the input for a strength meter and rules checklist
  • Idempotent: moving or re-inserting the field never adds a second toggle or meter

Validation Status Icons

Form fields automatically display a checkmark (valid) or X (invalid) after user interaction. Icons are positioned inside the input's padding. Use data-no-icon to disable them.

OTP/PIN Input

Use data-type="otp" on the input for verification codes. Progressive enhancement: works as a standard text input without JS, enhances to multi-box with JS.

  • Auto-focus moves to the next box after entering a digit
  • Backspace moves focus to the previous box
  • Arrow keys navigate between boxes
  • Paste and one-time-code autofill fill multiple boxes at once
  • The original input stays a real (visually hidden) text input: it submits the code and keeps required and the length check (a pattern of \d{length} is added when you don't supply one), so an empty or partial code blocks submission. Its partial-code message defaults to "Enter all {total} digits" (data-message-patternmismatch or data-label-incomplete to change it)
  • The boxes form a role="group" named by the field's <label> and described by its hints; autocomplete="one-time-code" moves to the first box. Box names default to "Digit 1 of 6" (data-label-digit="Ziffer {n} von {total}" to localize)

Output Message Classes

Use class="hint" and class="error" on output elements for different message types.

Class Visibility Use Case
.hint Always visible (hides when valid) Format requirements, help text
.error Only when invalid Error messages

Checkbox and Radio

Use data-type="checkbox" or data-type="radio" for inline label+input layout. Wrap radio groups in a <fieldset> with a <legend>.

CSS-Only Validation

Uses :user-valid and :user-invalid pseudo-classes to show validation states only after user interaction, preventing premature error states on page load.

JS-Enhanced Validation

Add data-validate to a <form> to enable features CSS can't handle: custom error messages, cross-field validation, checkbox group constraints, and error summaries. Without it, everything works as pure CSS validation.

Form Attributes

Attribute On Description
data-validate <form> Opt-in. No value = field-level errors (+ summary if present). "summary" = summary only.
data-submit <form> Submit mode: "native" (default), "event" (dispatches vb:submit), "fetch" (async with loading/success/error states).

Custom Error Message Attributes

Attribute names map directly to ValidityState keys. Place these on the input element.

Attribute ValidityState Key When Triggered
data-message-valuemissing valueMissing required field is empty
data-message-typemismatch typeMismatch type="email" / type="url" format wrong
data-message-patternmismatch patternMismatch pattern regex fails
data-message-tooshort tooShort Below minlength
data-message-toolong tooLong Above maxlength
data-message-rangeunderflow rangeUnderflow Below min
data-message-rangeoverflow rangeOverflow Above max
data-message-stepmismatch stepMismatch Not on step interval
data-message-badinput badInput The browser can't parse the entry (e.g. letters in type="number")
data-message-customerror customError setCustomValidity() was called; without this attribute the custom message itself is shown

Message order: the matching data-message-* → (for custom errors and custom elements) the control's own validationMessage → the text authored inside output.error → the browser's validationMessage → data-message-invalid.

Cross-Field and Group Attributes

Attribute On Description
data-match input ID of field that must have the same value
data-message-match input Custom message when data-match fails
data-min-checked fieldset Minimum number of checked checkboxes
data-max-checked fieldset Maximum number of checked checkboxes

Web Component API

<form-field> upgrades to a web component when JS loads. It provides these methods for programmatic use:

Method / Property Returns Description
validate({ show = true } = {}) boolean Validate the field and show the result immediately (no blur needed) — error text, data-invalid, aria-invalid, describedby. The form coordinator calls it on submit. { show: false } only returns validity.
setError(message) - Show a programmatic error (e.g. from server validation). Also sets it as the native control's custom validity so the form won't submit. Cleared on the user's next edit; a custom error set by other code (e.g. data-match) is never cleared by the field.
clearError() - Clear the field's programmatic error and return to the neutral state.
fieldName string Human-readable field name from the label or legend.
input HTMLElement The bound control: the native input/textarea/select, or the form-associated custom element.
form-field:upgraded (event) - Bubbles once the field has bound its control.

Timing: the field validates when focus leaves it (moving between its own parts — password toggle, OTP boxes, a combobox popup — doesn't count), then re-validates on every edit once an error has been shown. It also validates when the browser fires invalid (native submit, checkValidity()). Its state survives being moved in the DOM.

Custom Controls

A form-associated custom element inside the field — <date-picker>, <star-rating>, <combo-box> — becomes the bound control in preference to any native input inside it. The field reads its validity / validationMessage when exposed (date-picker), otherwise its :invalid state, and listens for its input, change, <tag>:change and invalid events. If the custom element is defined after the field upgrades, the field re-binds to it.

Put data-message-valuemissing on the custom element (or the field) for the required message; otherwise the authored error text is used.

setError() on a custom control is display-only (its validity lives in its own ElementInternals) and clears on the next change.

Error Summary

Add an <output class="error-summary"> inside your form for a consolidated list of all errors on submit.

Mode Attribute Behavior
Field-level only data-validate (no summary output) Errors appear inline next to each field
Summary only data-validate="summary" Summary at top, field-level errors hidden
Both data-validate + summary output present Summary at top AND inline errors on each field

Complete Contact Form

Why Use <output> for Messages?

  • Purpose-built: Represents the result of a calculation or user action
  • Native association: Has for attribute to link to input(s)
  • Accessible: Works naturally with aria-live for screen readers
  • No JavaScript required: Can show different states via CSS

Accessibility Checklist

  • Every <input> has a <label> with matching for/id
  • Required fields use the required attribute
  • Validation messages use <output> with aria-live="polite"
  • Inputs link to messages via aria-describedby (wired automatically on upgrade; author it too for the no-JS page)
  • The required asterisk is decorative and silent; the control's native required state is what screen readers announce
  • In forced-colors mode the state icons switch to system colours and invalid controls get a double border
  • Form controls have appropriate autocomplete values
  • Error states don't rely on color alone (include text)

Related

Enhancement attributes for the control inside

↑