Form
An enhanced native <form> supporting validation and submission of inner fields according to rules.
The data source is each field's
valueattribute (controlled mode). Fields validated by the form areoas-input/oas-textarea/oas-select/oas-auto-complete/oas-cascader/oas-tree-select/oas-input-number/oas-checkbox/oas-radiowith aname(group containers are not involved).oas-input/oas-textarea/oas-input-numberdo not automatically write back to thevalueattribute while typing — listen tooas-input/oas-changeevents in script to sync;oas-select/oas-cascader/oas-tree-selectwrite back by themselves on selection.
Feature Demo
The feature demo area only demonstrates field collection and submission, without validation rules.
Basic Usage
Collect & submit
Without rules, submission performs no validation and dispatches oas-submit directly, with detail.values carrying the collected results of all fields with a name.
Mixed Controls
Mixed controls
Validation
The validation area demonstrates rules-declared validation rules and failure feedback.
Validation rules:
{ required, message, minLength, maxLength, pattern }. On failure, the field is markedaria-invalid(red-bordered input), an error message is shown in red below the field, andoas-validate-failis dispatched.
Required & Format Validation
Required & format validation
Length Validation
minLength validation
Disabled Fields Skip Validation
Disabled fields are not validated
Submit & Validation-fail Events
submit / validate-fail
Grid Form Layout
With
layout="grid", the form element becomes a 24-column grid andoas-form-itemspans columns viaspan(default 24 = full row);gapcontrols grid spacing,label-alignpositions the label (left/right/top, defaulttop), andlabel-widthsets the label column width forleft/right. On validation failure, error messages are collected into theoas-form-itemerror slot (role="alert").
Two-Column Grid with Validation
Two-column grid layout
label-align & label-width
Switch label-align
Controlled syncing and event listeners (wired in one <script> block):
API
oas-form
| Attribute | Description | Type | Default |
|---|---|---|---|
gap | Grid spacing in grid mode (token value, e.g. var(--oas-space-4)) | string | 0 |
label-align | Label alignment: left / right / top (default top in grid mode) | string | top |
label-width | Label column width when label-align is left/right | — | — |
layout | Layout mode: vertical (default, stacked) / grid (24-column grid); non-enum values fall back to vertical | string | vertical |
rules | Validation rules JSON: { 字段名: [{ required, message, minLength, maxLength, pattern }] } | Rules | string | {} |
| Event | Description |
|---|---|
oas-submit | Validation passed, detail: { values } |
oas-validate-fail | Validation failed, detail: { errors, values } |
| Name | Description |
|---|---|
| default | — |
oas-form-item
| Attribute | Description | Type | Default |
|---|---|---|---|
label | Label text (no label row when omitted) | string | — |
name | Field name (validation association) | — | — |
required | Required asterisk (visual only; validation is still driven by form rules) | boolean | — |
span | Columns spanned in the 24-column grid (only when form layout="grid"; non-integer in 1-24 → 24) | string | 24 |
| Name | Description |
|---|---|
| default | Field control |
On validation failure, failed fields are marked aria-invalid; error messages can be retrieved via form.getErrors(). For fields wrapped in oas-form-item, the error text is collected into the form-item's error slot (role="alert").