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 modes remain consistent between SSR output and client hydration.
  • Static validation styles and error text can be rendered on the server.
  • Instance methods such as validate and async validation run after client activation.
  • Use a reactive form model in Nuxt pages to keep bindings and validation state synchronized.

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

Props

Form

PropDescriptionTypeDefault
modelReactive form model object.Record<string, unknown>Required
rulesValidation rules object.YhFormRules{}
label-widthLabel width.string | number''
label-positionLabel alignment mode.'left' | 'right' | 'top''right'
label-suffixSuffix appended after each label.string''
show-messageWhether validation messages are displayed.booleantrue
scroll-to-errorWhether the first invalid field is scrolled into view after validation fails.booleanfalse
scroll-into-view-optionsNative scrollIntoView options used when scrolling to an invalid field.boolean | ScrollIntoViewOptionsfalse
scroll-to-error-offsetTop offset used by scroll-to-error.number0
disabledWhether all form controls inherit the disabled state.booleanfalse
hide-required-asteriskWhether required marks are hidden.booleanfalse
sizeShared control size.'large' | 'default' | 'small''default'
status-iconWhether validation status icons are shown.booleanfalse
layoutForm layout mode.'horizontal' | 'vertical' | 'inline''horizontal'
theme-overridesComponent-level theme overrides for YhForm.ComponentThemeVarsundefined

Form Item

PropDescriptionTypeDefault
propField path in the parent form model. Supports nested paths such as user.profile.name.string''
labelLabel text.string''
label-widthLabel width override.string | number''
requiredWhether the item is required.booleanfalse
rulesItem-level validation rules.YhFormRule | YhFormRule[][]
show-messageWhether this item displays validation error text.booleantrue
sizeSize override for the current item.'large' | 'default' | 'small' | ''''
validate-triggerValidation trigger override.string | string[]''
error-positionAlignment of the validation message.'left' | 'center' | 'right''left'
disabledWhether the current item is disabled.booleanfalse
validate-statusManual validation status override.'' | 'success' | 'error' | 'validating'''
errorManual validation message override.string''
theme-overridesComponent-level theme overrides for YhFormItem.ComponentThemeVarsundefined

Form Schema

PropDescriptionTypeDefault
modelValueBound schema model value.Record<string, unknown>Required
schemaSchema configuration list.(YhFormSchemaItem | YhFormSchemaGroup)[][]
formPropsProps forwarded to YhForm.Partial<YhFormProps>{}
gutterGrid spacing in pixels.number20

Events

Form

Event NameDescriptionType
validateTriggered after a validation run completes.(isValid: boolean, invalidFields?: Record<string, unknown>) => void

Form Item

Current component does not expose component events.

Form Schema

Event NameDescriptionType
update:modelValueTriggered when the schema model changes.(value: Record<string, unknown>) => void
submitTriggered when the internal form is submitted.(value: Record<string, unknown>) => void
changeTriggered when a schema field changes.(field: string, value: unknown, model: Record<string, unknown>) => void
validateForwarded form validation result.(isValid: boolean, invalidFields?: Record<string, unknown>) => void

Slots

Form

Slot NameDescriptionParameters
defaultForm content.-

Form Item

Slot NameDescriptionParameters
defaultForm control content.-
labelCustom label content.-

Form Schema

Slot NameDescriptionParameters
field-{fieldName}Custom rendering for a specific schema field.{ model, item, handleUpdate }
label-{fieldName}Custom label rendering for a specific schema field.{ model, item }
footerFooter action area.{ model, formRef }
field-{listField}-{subField}Custom renderer for a list-row sub-field.{ row, index, item }
list-footer-{listField}Content rendered after the add button of a list field.{ model, item }

Expose

Form

NameDescriptionType
validateValidates the whole form or specific fields.(props?: string | string[] | ((isValid: boolean, invalidFields?: Record<string, unknown>) => void), callback?: (isValid: boolean, invalidFields?: Record<string, unknown>) => void) => Promise<boolean>
resetFieldsResets all fields or specific fields.(props?: string | string[]) => void
clearValidateClears validation results.(props?: string | string[]) => void
scrollToFieldScrolls to a specific field.(prop: string) => void

Form Item

NameDescriptionType
validateValidates the current form item.(trigger?: string, callback?: (isValid: boolean) => void) => Promise<boolean>
resetFieldResets the current item value and validation state.() => void
clearValidateClears the current item validation state.() => void
validateStatusCurrent validation status.ComputedRef<'' | 'success' | 'error' | 'validating'>
validateMessageCurrent validation message.ComputedRef<string>
sizeResolved item size.ComputedRef<string>

Form Schema

NameDescriptionType
validateValidates the schema form or specific fields.(fields?: string | string[], callback?: (isValid: boolean) => void) => Promise<boolean | undefined>
resetFieldsResets schema fields.(fields?: string | string[]) => void
clearValidateClears schema validation results.(fields?: string | string[]) => void
scrollToFieldScrolls to a schema field.(field: string) => void
getModelReturns the current schema model snapshot.() => Record<string, unknown>
setFieldValueUpdates a single schema field value.(field: string, value: unknown) => void
formRefUnderlying YhForm instance ref.Ref<YhFormInstance | undefined>

Types

Form Schema Item

PropDescriptionTypeDefault
fieldField path, supports nested paths.stringRequired
labelField label.stringundefined
typeSchema item type.'default' | 'divider' | 'text' | 'list''default'
componentComponent name or Vue component.string | Componentundefined
propsProps passed to the rendered field component. Supports a function form.Record<string, unknown> | (model: Record<string, unknown>) => Record<string, unknown>undefined
formItemPropsExtra props passed to YhFormItem.Partial<YhFormItemProps>undefined
rulesValidation rules or a rule factory based on the current model.YhFormRule[] | (model: Record<string, unknown>) => YhFormRule[]undefined
requiredRequired shorthand or required factory.boolean | (model: Record<string, unknown>) => booleanfalse
hiddenWhether the field is hidden. Supports a function form.boolean | (model: Record<string, unknown>) => booleanfalse
disabledWhether the field is disabled. Supports a function form.boolean | (model: Record<string, unknown>) => booleanundefined
slotsSlot component mapping used by schema rendering.Record<string, unknown>undefined
colGrid span from 1 to 24.number24
spanCustom grid-column span.numberundefined
renderCustom render function.(model: Record<string, unknown>) => VNode | Component | nullundefined
asyncOptionsAsync option loader for option-based components.() => Promise<Record<string, unknown>[]>undefined
optionPropProp name that receives async options.string'options'
defaultValueDefault field value used when the model field is undefined.unknownundefined
tooltipTooltip text displayed next to the label.stringundefined
emptyValuePlaceholder used by type: 'text' when the value is empty.string'-'
listSchemaChild schema used by type: 'list'.YhFormSchemaItem[]undefined
listPropsControls used by type: 'list'.{ addButtonText?: string; allowDelete?: boolean | ((model: Record<string, unknown>, index: number) => boolean); allowAdd?: boolean | ((model: Record<string, unknown>) => boolean); max?: number; min?: number }undefined

Form Schema Group

PropDescriptionTypeDefault
titleGroup title.stringundefined
itemsItems rendered inside the group.YhFormSchemaItem[][]
propsExtra props passed to the wrapping fieldset.Record<string, unknown>undefined
collapsibleWhether the group supports collapse/expand interaction.booleanfalse
collapsedInitial collapsed state.booleanfalse

Theme Variables

YhForm and YhFormItem support themeOverrides. Their runtime styles consume the following component variables:

VariableDescriptionDefault
--yh-form-item-heightBase height used by form items and aligned controls.32px
--yh-form-item-margin-bottomBottom spacing between form items.22px
--yh-form-label-font-sizeForm label font size.14px

YhFormSchema mainly reuses form and global theme tokens and does not define extra dedicated component variables.

Type Exports

NameDescription
YhFormPropsProps type for YhForm
YhFormItemPropsProps type for YhFormItem
YhFormSchemaPropsProps type for YhFormSchema
YhFormSchemaItemSchema form item type
YhFormSchemaGroupSchema form group type
YhFormRuleSingle validation rule type
YhFormRulesForm rules collection type
YhFormInstancePublic instance type for YhForm
YhFormItemInstancePublic instance type for YhFormItem
YhFormSchemaInstancePublic instance type for YhFormSchema

Released under the MIT License.