Skip to content

Form

Consists of input fields, selectors, radio buttons, checkboxes, and other controls, used for collecting, validating, and submitting data.

Basic Usage

Includes various layouts, sizes, and basic required field validation.

Basic Usage

Typical Form

Contains multiple types of form fields, demonstrating complex interactions and linked validation.

Typical Form

Inline Form

Setting layout="inline" allows form items to be arranged horizontally. Label and Input are precisely aligned vertically via Flex layout.

Inline Form

Grid Layout

Utilizing the built-in 24-grid system, you can easily achieve complex responsive form layouts.

Grid Layout

Validation Feedback

After setting status-icon, validation result icons will be displayed on components like input fields and selectors.

Validation Icon

Nested Fields

Supports nested object path configuration, such as user.info.name.

Nested Fields

Schema Driven (Dynamic Form)

Schema-driven form rendering with full support for grouping, grid layout, async data, conditional visibility, and custom slots.

Validation Notes

  • required: true automatically adds mandatory constraints. For components like Switch (Boolean), it is recommended to use validator within rules for precise control and to avoid message conflicts.
  • rules array supports fine-grained configuration of regex, length, custom functions, and other logic.
  • formRef.validate() triggers complete validation for all registered fields.

Basic Schema

Configure the schema array to generate a form with required shorthand and footer slot bound to formRef.validate() for form validation.

Basic Info
Slot
Basic Schema Usage

Advanced Schema (Async/Linkage/Collapse/Tooltip)

asyncOptions loads options asynchronously (auto-injects loading), props functions for field linkage, collapsible for collapsible groups, tooltip for field hints.

Product Config (Collapsible)
Remarks
Dynamic Linkage Demo
Advanced Features

Field Type Extensions (divider / text / list / render)

  • type: 'divider' inserts a separator line
  • type: 'text' renders the field value as read-only, with emptyValue for placeholder when empty (default '-')
  • type: 'list' enables dynamic add/remove sub-item lists. Use listSchema to define sub-fields and listProps for controls.
  • render function for fully custom rendering
Basic Info
Alice
Engineering
Not set
Editable Content
Current City: Not set
Field Type Extensions (divider / text / emptyValue / render)

Dynamic List (type: 'list')

Use type: 'list' to handle scenarios like a "contacts" dynamic list. listProps.max/min constrain how many items can be added or removed. Each row fully supports FormSchemaItem config including linked props and validation rules.

Dynamic List

Scroll Offset (scroll-to-error-offset)

In pages with a fixed top navigation bar, scrolling to the first error item after validation failure might be obscured by the sticky header. Configure scroll-to-error-offset to set the top offset (in px):

The following is a long form. When you scroll to the bottom and click validate, the page will smoothly scroll back to the first error field. Thanks to the scroll-to-error-offset="64" configuration, the error field will not be obscured by the browser's top bar.
Scroll Offset

Use in Nuxt

The Form component and its sub-components (FormItem, FormSchema) fully support Nuxt 3/4 SSR rendering. When used in a Nuxt project, all form components are automatically imported.

Use in Nuxt

SSR Notes:

  • ✅ Form layout (horizontal, vertical, inline) remains perfectly consistent in SSR.
  • ✅ Validation error state (is-error) and error messages support server-side rendering.
  • ✅ Static validation rules take effect on the server (error styles present on first screen).
  • ⚠️ Submission validation (validate method) and dynamic async validation are only available after client-side activation.
  • 💡 It is recommended to use reactive to define the form model in Nuxt pages to maintain reactivity continuity.

SSR Safety

The internal IDs and ARIA attributes generated by the Form component are based on useId, ensuring that in highly nested form structures, the server and client HTML associations are perfectly consistent, triggering no hydration warnings.

API

Form Props

PropDescriptionTypeDefault
modelForm data objectobject
rulesForm validation rulesobject
label-widthLabel widthstring | number
label-positionLabel position'left' | 'right' | 'top''right'
layoutLayout mode'horizontal' | 'vertical' | 'inline''horizontal'
disabledWhether to disable all components in the formbooleanfalse
sizeUnified size'large' | 'default' | 'small''default'
status-iconWhether to display validation result feedback icons in input fieldsbooleanfalse
scroll-to-errorWhether to scroll to the first error item when validation failsbooleanfalse
scroll-into-view-optionsScroll configuration itemsobject | boolean{ behavior: 'smooth', block: 'center' }
scroll-to-error-offsetTop offset (px) for scroll-to-error, prevents overlap with sticky headersnumber0

Form Methods

MethodDescriptionParameters
validateValidates the form, supports partial validation(props?: string | string[], callback?: Function)
resetFieldsResets the form, supports partial reset(props?: string | string[])
clearValidateRemoves validation results for form items(props?: string | string[])
scrollToFieldScrolls to a specified field(prop: string)

FormItem Props

PropDescriptionTypeDefault
propForm field model key, supports nested paths (a.b.c)string
labelLabel textstring
label-widthLabel widthstring | number
requiredWhether it is requiredbooleanfalse
rulesValidation rulesobject | array
sizeConfigure size for the form item (overrides Form setting)'large' | 'default' | 'small'
error-positionError message alignment'left' | 'center' | 'right''left'
show-messageWhether to show validation error messagesbooleantrue
disabledDisables current item (overrides Form setting)booleanfalse

FormSchema Props

PropDescriptionTypeDefault
modelValueBinding value (v-model)object
schemaForm configuration items, supports grouping and gridsarray[]
formPropsProps passed through to YhForm (same as Form Props)object{}
gutterGrid column spacing (px)number20

FormSchema Methods

MethodDescriptionParameters
validateTriggers form validation, supports partial(fields?: string | string[], callback?: Function)
resetFieldsResets field values and validation state(fields?: string | string[])
clearValidateClears validation results, supports partial(fields?: string | string[])
scrollToFieldScrolls to specified field(field: string)
getModelReturns current form data snapshot() => Record<string, unknown>
setFieldValueDynamically updates a single field value(field: string, value: unknown)

FormSchema Slots

Slot NameDescriptionSlot Props
field-{fieldName}Custom rendering for a specific field{ model, item, handleUpdate }
label-{fieldName}Custom label rendering for a field{ model, item }
footerForm footer action area{ model, formRef }
field-{listField}-{subField}Custom render for a sub-field within a list row{ row, index, item }
list-footer-{listField}Area after the add-button in a list field{ model, item }

FormSchemaItem (Configuration Item)

PropDescriptionTypeDefault
fieldField name, supports nested paths (a.b.c)string
labelLabel namestring
typeField type: 'default' normal, 'divider' separator, 'text' read-only, 'list' dynamic list'default' | 'divider' | 'text' | 'list''default'
componentComponent name (input, radio, select, etc.) or Vue Component objectstring | Component
colGrid span (1-24)number24
propsProps for internal component, supports functional linkageobject | (model) => object
formItemPropsProps passed through to form-itemobject
requiredRequired (auto-adds required rule, no need to write rules)booleanfalse
rulesValidation rules (merged with required)FormRule | FormRule[]
disabledWhether disabled (supports functional linkage)boolean | (model) => boolean
hiddenWhether hidden (supports functional linkage)boolean | (model) => booleanfalse
defaultValueDefault field value (applied when field value is undefined)unknown
tooltipTooltip text shown next to field labelstring
slotsComponent slot config (key: slot name, value: component object)object
renderCustom render function (lower priority than field-{name} slot)(model) => VNode | Component
asyncOptionsAsync options loader (auto-injects loading state)() => Promise<object[]>
optionPropProp name for receiving async options datastring'options'
emptyValuePlaceholder for type: 'text' when value is null/undefined/''string'-'
listSchemaSub-field schema for type: 'list'FormSchemaItem[]
listPropsControls for type: 'list' (max/min/addButtonText/allowAdd/allowDelete)object

FormSchemaGroup (Group Config)

PropDescriptionTypeDefault
titleGroup titlestring
itemsForm items within the groupFormSchemaItem[][]
propsProps passed through to fieldsetobject
collapsibleWhether to enable collapsible featurebooleanfalse
collapsedDefault collapsed statebooleanfalse

Released under the MIT License.