Form

Form container with renderers, nested items, a 24-column grid, and stable error space.

Form

Overview

Form supports both declarative slots and schema-driven items. The configuration API follows the useful VxeUI children + itemRender pattern: Form owns model and validation orchestration while renderers connect values, component props, and events.

Validation and triggers

Validation is implemented inside Form without an external validation runtime. Rules support required and synchronous or asynchronous validator(value, model) functions.

  • When trigger is omitted, interaction validation defaults to blur.
  • blur runs when focus leaves the complete Form Item, rather than while moving between controls inside it.
  • change watches the actual field model value, so declarative Items and schema renderers share the same behavior.
  • validate(), validateField(), and form submission run applicable rules directly; submission ignores the interaction trigger and validates all rules.

Headless validation

createFormValidator(model, { rules, items }) runs the same rule format without mounting SForm or creating DOM. Use it for lazy content, pre-submit checks, and data that is not currently rendered. validate() returns { valid, errors }; validateField(field) returns one field result.

Size

Compare the inherited small, default, and large component sizes.

Schema renderers and nested layout

children can recurse to any depth and every level uses 24 proportional units. Item widths account for the configured gap between items. Responsive spans follow the width of their containing form row, including nested rows, rather than the browser window: xs below 480px, sm from 480px, md from 768px, lg from 1024px, and xl from 1280px. A numeric span uses a full row below 768px; pass { xs, sm, md, lg, xl } for precise responsive sizing. Use the built-in $input, $select, $switch, and $textarea names directly in itemRender; $buttons can provide Form submit and reset actions without rebuilding an action slot.

Custom renderer

Reusable project renderers are registered once from the application entry. The example below only references $uppercaseInput, which this documentation site registered globally outside the component. See Renderer for registration, callback contracts, usage in Form and Table, and built-in mappings.

Declarative nested items

The existing <s-form-item> API remains compatible. Add nested to a parent Item, place child Items directly inside it, and use span for layout.

Container responsive layout

Switch the container width to see fields change from full rows to two columns in the same browser window. This example uses { xs: 24, sm: 12 } with the default 16px column gap.

API

SForm props

Property
Type
Values
Description
default
Example
More
model
Object
reactive form data
Required. The single data source read and written by field paths.
—
—
size
medium / small / large
Default size inherited by schema renderers and slotted controls unless they declare their own size.
—
—
rules
{ [field]: FormRule | FormRule[] }
Required, custom validator, and blur / change trigger rules.
{}
—
items
[]
tree configuration with children
Render schema-driven items; each node accepts SFormItem fields plus the items[] options below.
[]
—
label-width
String | Number
CSS width
Default label width for horizontal items; fits four CJK characters plus the required marker.
calc(4em + 24px)
—
label-position
String
left / right / top
Default label placement for child Form Items.
right
—
label-align
String
left / right
Default text alignment inside horizontal labels.
right
—
inline
Boolean
true / false
Use the inline Form layout.
false
—
disabled
Boolean
true / false
Disable all declarative and schema-rendered fields.
false
—
readonly
Boolean
true / false
Make all declarative and schema-rendered fields readonly.
false
—
show-message
Boolean
true / false
Display validation errors and field descriptions.
true
—
reserve-error-space
Boolean
true / false
Reserve stable space for errors or helper text to prevent layout shift.
true
—
scroll-to-error
Boolean
true / false
Focus and scroll to the first invalid field.
true
—
column-gap
String | Number
CSS size
Horizontal gap in the 24-column Form grid.
16
—
row-gap
String | Number
CSS size
Vertical gap in the 24-column Form grid.
4
—

SFormItem props

Property
Type
Values
Description
default
Example
More
label
String
—
Field label. Takes precedence over title.
—
—
title
String
—
Compatibility alias used when label is absent.
—
—
prop
String
deep model path
Field path such as profile.name. Takes precedence over field.
—
—
field
String
deep model path
Compatibility alias used when prop is absent.
—
—
id
String
—
Control id used by the generated label association.
generated
—
description
String
—
Helper text shown when the field has no validation error.
—
—
rules
| []
—
Item-level rules; override SForm rules for this field.
—
—
required
Boolean
true / false
Display the required state independently of validation rules.
false
—
label-width
String | Number
CSS width
Override SForm label-width for this Item.
inherited
—
label-position
String
left / right / top
Override SForm label-position for this Item.
inherited
—
span
Number | 
1–24 / responsive object
Width occupied by this Item in the 24-column grid.
24
—
vertical
Boolean
true / false
Place this Item label above its control.
false
—
nested
Boolean
true / false
Treat the default slot as a nested Form Item grid.
false
—
align
String
left / center / right
Align the Item content within its grid cell.
left
—
reserve-error-space
Boolean
true / false
Override SForm reserve-error-space for this Item.
inherited
—
disabled
Boolean
true / false
Override the disabled state passed to itemRender.
inherited
—
readonly
Boolean
true / false
Override the readonly state passed to itemRender.
inherited
—
item-render
—
Render a registered or custom control when no default slot is supplied.
—
—

items[] configuration (FormItemConfig)

Field
Type
Description
default
Example
More
key
string | number
Stable Vue key for an items node; prop, field, then index are the fallbacks.
—
children
[]
Recursively creates nested Form Item grids.
—
visible
boolean
Statically controls whether this configuration node renders.
true
visibleMethod
({ model, item }) => boolean
Dynamically decides whether the node renders from its model and configuration.
—
disabled
boolean | (model) => boolean
Overrides or derives the disabled state for this configuration node.
inherited
readonly
boolean | (model) => boolean
Overrides or derives the readonly state for this configuration node.
inherited
class
string | string[] | Record<string, boolean>
Class forwarded to the generated Form Item.
—
style
CSSProperties
Inline style forwarded to the generated Form Item.
—
slots
{ label?: string; default?: string; error?: string }
Names scoped slots declared on SForm for this configuration node.
—

Validation rules (FormRule)

Rule
Type
Description
default
Example
More
required
boolean
Rejects undefined, null, an empty string, or an empty array.
false
message
string
Fallback for required failure or a validator returning false; a returned error string takes precedence.
—
validator
(value, model) => boolean | string | Promise<boolean | string>
Returns true when valid, false for the fallback message, or an error string to display.
—
trigger
'blur' | 'change' | Array<'blur' | 'change'>
Interaction trigger; omitted rules run on blur and all rules run on submit.
—

Renderer options (RendererOptions)

Option
Type
Description
default
Example
More
name
string
Required name of a registered renderer.
—
component
Component | string
Overrides the component registered under name.
—
props
Record<string, unknown>
Component props forwarded to the rendered control.
—
attrs
Record<string, unknown>
Additional HTML or component attributes.
—
events
Record<string, (params, ...args) => unknown>
Event handlers receiving the renderer context before component event arguments.
—
modelProp
string
Model prop for a custom control; the Form field value overrides a same-named prop.
modelValue
modelEvent
string
Model update event; its first argument is written directly to the Form field.
update:modelValue
content
string | (params) => VNodeChild
Default slot text or a content rendering function.
—
options
unknown[]
Options forwarded to data-driven controls such as Select and Radio Group.
—
optionProps
Record<string, string>
Option field mapping available to custom renderers.
—
children
[]
Nested rendering nodes for composite controls.
—

SForm events

Event
Type
Description
default
Example
More
validate
—
Fired after a field validates with field, valid, and message.
—
—
submit
—
Fired with model and native event after submission passes validation.
—
—
invalid-submit
—
Fired with errors, model, and native event after submission fails validation.
—
—
reset
—
Fired after native reset restores initial values.
—
—

SLOTS

Slot
Scope
Description
default
Example
More
SForm.default
—
Compose Form Item controls or nested schema content.
—
—
SFormItem.default
{ id: string; error: string; validate: (trigger?: | 'submit') => Promise<boolean> }
Render the field control using its generated id, validation message, and validation action.
—
—
SFormItem.label
{ id: string; label: string; required: boolean }
Customize the field label and required state.
—
—
SFormItem.error
{ error: string; description: string | undefined }
Customize validation and helper content.
—
—
items[].slots.default
{ model: ; size: string; item: ; field: string | undefined; prop: string | undefined; value: unknown; disabled: boolean; readonly: boolean; setValue: (value: unknown) => void; id: string }
Render a configured field using the current model and value setter.
—
—
items[].slots.label
{ model: ; size: string; item: ; field: string | undefined; prop: string | undefined; value: unknown; disabled: boolean; readonly: boolean; setValue: (value: unknown) => void; id: string; label: string; required: boolean }
Render a configured field label with its model context.
—
—
items[].slots.error
{ model: ; size: string; item: ; field: string | undefined; prop: string | undefined; value: unknown; disabled: boolean; readonly: boolean; setValue: (value: unknown) => void; error: string; description: string | undefined }
Render a configured field's error or helper content.
—
—

SForm exposed methods

Method
Type
Description
default
Example
More
validate
() => Promise<boolean>
Validate every registered field.
—
—
validateField
(prop: string, trigger?) => Promise<boolean>
Validate one field path.
—
—
clearValidate
(props?: string | string[]) => void
Clear validation state for selected or all fields.
—
—
resetFields
(event?: Event) => void
Restore initial model values and clear errors.
—
—
submit
(event?: Event) => Promise<boolean>
Validate and emit submit or invalid-submit.
—
—
getErrors
() => Record<string, string>
Return the current field error map.
—
—
Last Updated: 2026-10-28, 06:17:56 UTC
Copied