Skip to content

DynamicForm

Dynamic form component for quickly building form interfaces based on configuration.

TIP

In addition to the full dynamic form component, we also provide a standalone EzFormItem component that can be used to build custom form layouts.

Overview

DynamicForm is designed for building forms in a configuration-driven way. Compared with writing a large number of el-form-item blocks manually, it is better suited for business forms with many fields, relatively regular structure, and frequent iteration.

It mainly helps with these scenarios:

  • Use items as a single-group shorthand for lightweight form scenarios.
  • Use groups as the full configuration model for sectioned forms with titles, descriptions, group-level layout, and group-level slots.
  • Reuse built-in field types, required rules, visibility linkage, and disabled linkage to reduce repetitive boilerplate.
  • Keep both field-level and group-level slots, so you can move between standardized configuration and high customization when needed.

Recommended usage:

  • Use groups as the standard long-term configuration mode.
  • Use items only as a shorthand for simple single-section forms or lightweight query areas.
  • If one area becomes too custom for configuration-driven rendering, combine EzFormItem or group slots for that part.

Basic Usage

Component Types

Form Validation

Custom Slots

Grouped Form

Field Serialization

Attributes

AttributeDescriptionTypeRequiredDefault
v-modelTwo-way bound form dataRecordNo{}
itemsShorthand config for a single-group formFormItemConfig[]No[]
groupsStandard grouped configuration (recommended)FormGroupConfig[]No[]
colsGrid layout columnsnumberNo1
gutterGrid spacingnumberNo20
Other Form PropsPassed through to el-formPartialNo-

FormItemConfig

AttributeDescriptionTypeRequiredDefault
propField namestringYes-
labelLabelstringNo-
typeComponent type. Built-in branches only accept FormItemType literals; custom rendering should use componentFormItemTypeNo-
defaultValueDefault valueanyNo-
rulesValidation rulesFormItemRuleNo-
requiredRequiredbooleanNofalse
requiredMessageRequired messagestringNo-
spanOccupied grid columnsnumberNo-
hiddenHiddenbooleanNofalse
disabledDisabledbooleanNofalse
placeholderPlaceholderstringNo-
optionsOption configuration. Select supports grouped options, radio/checkbox use their wrapped option types, and tree-select/cascader pass structured data sources throughFormItemOption[]No-
attrsComponent attributes passed to the rendered control. select/radio/checkbox/upload-images, tree-select, and cascader expose more specific public prop subsets; other built-in controls are still loosely forwardedRecordNo-
componentCustom field component. It should follow the modelValue / update:modelValue / disabled field contractComponentNo-
itemAttrsAdditional el-form-item attributesPartial<FormItemProps>No-
showLinkage display conditionFunctionNo-
disabledWhenLinkage disable conditionFunctionNo-
serializeField serializer before submitFunctionNo-
deserializeField deserializer when restoring external dataFunctionNo-

FormGroupConfig

AttributeDescriptionTypeRequiredDefault
nameUnique group keystringNo-
titleGroup titlestringNo-
descriptionGroup descriptionstringNo-
itemsItems in this groupFormItemConfig[]Yes[]
colsGrid columns inside this groupnumberNoInherit global cols
gutterGrid spacing inside this groupnumberNoInherit global gutter
hiddenHide this groupbooleanNofalse
showGroup visibility conditionFunctionNo-
classNameGroup container classstringNo-
styleGroup container stylestring | RecordNo-
headerClassNameGroup header classstringNo-
headerStyleGroup header stylestring | RecordNo-
bodyClassNameGroup body classstringNo-
bodyStyleGroup body stylestring | RecordNo-
headerSlotCustom group header slot namestringNogroup-header-${name}
slotCustom group content slot namestringNogroup-${name}

Data Initialization and v-model

  • v-model: Use standard Vue 3 two-way binding. Field changes are synced back to the parent model.
  • defaultValue: A config default is only applied when the corresponding field does not exist in the bound model.
  • items / groups are exclusive: items and groups cannot be provided at the same time. The component throws immediately when both are present.
  • Mode positioning: groups is the full configuration model. items is only a shorthand for a single-group form and will not gain group-level capabilities.
  • Type narrowing: FormItemConfig now narrows attrs/options for select, radio, checkbox, tree-select, cascader, upload-images, and component branches instead of treating every field shape as the same loose object. tree-select and cascader now also use stable attrs subsets.
  • Custom component contract: the component branch is no longer treated as an arbitrary component slot; it is expected to behave like a field component.

Data Flow Design

This component supports standard Vue 3 v-model two-way binding:

  • Use v-model as the source of truth for business state.
  • Use getFormData() to retrieve a deep-cloned snapshot of the current form state.
  • Use getSubmitData() to retrieve the submit payload after field-level serialize is applied.
  • Use setFormData() to merge or replace form values explicitly.
  • Use setSubmitData() to restore submit payload data back into the UI model with deserialize. Extra payload fields that are not declared as form props will not be written into v-model.
  • Use captureInitialData() to store the current state as the new reset baseline.
  • Use resetForm() to restore the form back to the current baseline.

Notes

  • The component automatically fills missing prop keys declared in items or groups, so Element Plus validation can track those fields reliably.
  • Replacing the bound v-model object from outside is supported; the component will normalize the structure again after replacement.
  • setFormData() clears current validation state after updating the data.
  • getSubmitData() does not mutate the current v-model; it only returns a transformed copy.
  • setSubmitData() only writes back declared form fields, so request-only fields such as split date keys can stay outside the UI model.
  • After the initial mount finishes, the component stores an initial snapshot automatically. resetForm() restores that snapshot by default.

FormItemType

NameDescription
INPUTInput
TEXTAREATextarea
NUMBERNumber Input
PASSWORDPassword Input
SELECTSelect (wrapped component)
RADIORadio (wrapped component)
CHECKBOXCheckbox (wrapped component)
DATEDate Picker
DATETIMEDateTime Picker
DATERANGEDate Range
DATETIMERANGEDateTime Range
TIMETime Picker
TIMERANGETime Range
UPLOAD_IMAGESImage Upload (wrapped component)
SWITCHSwitch
TREE_SELECTTree Select
CASCADERCascader
SLIDERSlider
RATERate

Methods

MethodDescriptionType
validateValidate formFunction
validateFieldValidate specified fieldsFunction
clearValidateClear validationFunction
getFormDataGet form data (call on demand)Function
getSubmitDataGet serialized submit payloadFunction
setFormDataSet form data (auto clear validation, support merge or replace)Function
setSubmitDataSet submit payload and deserialize it into the UI modelFunction
resetFormReset the form to the current baselineFunction
captureInitialDataStore the current form state as the new baselineFunction

Slots

NameDescriptionParameters
[prop]Custom form item content{ item: FormItemConfig, value: any, formData: Record }
label-[prop]Custom form item label{ item: FormItemConfig }
group-headerShared group header slot{ group: FormGroupConfig, index: number, items: FormItemConfig[], formData: Record }
groupShared group content slot{ group: FormGroupConfig, index: number, items: FormItemConfig[], formData: Record }
group-header-[name]Named group header slot{ group: FormGroupConfig, index: number, items: FormItemConfig[], formData: Record }
group-[name]Named group content slot{ group: FormGroupConfig, index: number, items: FormItemConfig[], formData: Record }

Released under the MIT License