Field
Introduction
A foundational input control designed to manage forms cleanly and accessibly. It aggregates input labels, contextual helper texts, dynamic error validation states, and custom JS-based rule checking into a cohesive, developer-friendly interface.
The Field component is fully integrated as an interactive field block inside the Page Builder. This allows content creators and designers to draft fields, place custom HTML form inputs, and supply instant client-side validation logic directly from Sveltia CMS without writing layout boilerplate.
Usage
These examples illustrate how content editors bind and configure form field structures.
1. Standard Input Field
A standard text field featuring a companion label, placeholder prompt, and a description helper text located directly below the input element.
{
"type": "field",
"label": "Username",
"placeholder": "e.g. jules_architect",
"helperText": "Choose a unique public username.",
"name": "username",
"interactive": true
}
2. Dynamic Input with Client-Side Validation
Utilises custom validation logic. When the user inputs fewer than 5 characters or skips the @ sign, an error message is automatically displayed and announced dynamically.
{
"type": "field",
"label": "Email Address",
"placeholder": "architect@domain.com",
"defaultValue": "invalid-email",
"validator": "(value) => value.includes('@') || 'Must be a valid email containing \'@\''",
"name": "email",
"interactive": true
}
3. Required & Disabled Option Fields
Demonstrates form field styles under standard HTML block states. This helps content writers visualise how fields look when they are mandatory (asterisk indicator) or locked due to permissions.
{
"type": "field",
"label": "Secret Key",
"defaultValue": "SUPER_SECURE_TOKEN",
"readOnly": true,
"required": true,
"interactive": true
}
Props
| Property | CMS Field Type | Default | Description / Supported Options |
|---|---|---|---|
Label Text (label) | string | - | The visual title or description positioned directly above the input element. |
Name (name) | string | - | Standard HTML name attribute sent with form submissions. |
Placeholder (placeholder) | string | - | Light placeholder text shown inside the input when it's completely empty. |
Helper Text (helperText) | string | - | Contextual hint or instruction text printed beneath the input field. |
Error Text (errorText) | string | - | Manual error message override. Triggers invalid styling and screen-reader announcements. |
Default Value (defaultValue) | string | - | Pre-populates the input on page load. Forces client-side interactive island mode. |
Required (required) | boolean | false | Renders a red asterisk indicator signaling that this input must not be left empty. |
Disabled (disabled) | boolean | false | Prevents all typing or cursor interaction and dims the entire field. |
Read Only (readOnly) | boolean | false | Keeps the value selectable and tab-focused but prevents editing of the text. |
Invalid State (invalid) | boolean | false | Explicitly forces the field into an error state, highlighting borders in red. |
| Validator Expression (validator) | string | - | Advanced JavaScript function expression evaluating the string input. Reconstructed client-side via new Function().
Example: `(value) => value.includes('@') \ | \ | 'Invalid email address'` |
| Force Interactive (interactive) | boolean | true | Ensures client-side hydration as an interactive island to support real-time user validation. |
Developer Notes & Accessibility
- Smart Switcher Hydration: By default, if the field is standard static presentation with no custom validation triggers or dynamic bindings, it remains lightweight static SSR markup. Providing any of
validator,defaultValue, or"interactive": trueautomatically promotes the element to a fully hydrated client-side island. - WAI-ARIA Descriptive Connections: The wrapper element dynamically manages aria connections. The input element automatically registers
aria-describedbypointing to the exact generated IDs of both the helper text and error text slots. - Attribute Leakage Prevention: The
FieldRootprimitive includes built-in filters to prevent standard input properties (likeplaceholder,autocomplete, orname) from leaking onto the outer wrapper<div>, ensuring completely valid, clean HTML output. - Compositional Context: The Field component supports a compositional architecture. When nesting sub-elements (like custom
Textareaor custom select elements) as children in the Page Builder, they automatically consume the outer Field's shared context to resolve appropriate validation attributes.