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.

Basic Usage

Component Types

Form Validation

Custom Slots

Attributes

AttributeDescriptionTypeRequiredDefault
model-valueInitial form dataRecordNo-
itemsForm configuration itemsFormItemConfig[]Yes[]
colsGrid layout columnsnumberNo1
gutterGrid spacingnumberNo20
formPropsel-form attributesPartialNo-

FormItemConfig

AttributeDescriptionTypeRequiredDefault
propField namestringYes-
labelLabelstringNo-
typeComponent typeFormItemType | stringNo-
defaultValueDefault valueanyNo-
rulesValidation rulesFormItemRuleNo-
requiredRequiredbooleanNofalse
requiredMessageRequired messagestringNo-
spanOccupied grid columnsnumberNo-
hiddenHiddenbooleanNofalse
disabledDisabledbooleanNofalse
placeholderPlaceholderstringNo-
optionsOption configurationFormItemOption[]No-
attrsComponent attributes (pass through to specific component)RecordNo-
componentCustom componentComponentNo-
itemAttrsAdditional el-form-item attributesRecordNo-
showLinkage display conditionFunctionNo-
disabledWhenLinkage disable conditionFunctionNo-

Data Initialization Priority

  • model-value: External initial data, highest priority
  • defaultValue: Default value in config, only takes effect when field not exists in model-value

Data Flow Design

This component uses unidirectional data flow + method control design:

  • model-value is only for initialization, no two-way binding
  • Use getFormData() to get form data on demand (e.g., on submit)
  • Use setFormData() to explicitly set data (auto clear validation)
  • This design ensures clear data flow and optimal performance, suitable for complex form scenarios

Breaking change

As of this version the component no longer automatically watches or two-way-syncs model-value (it will not emit update:modelValue).

  • To update the form from outside, call the component instance method setFormData(data, merge?: boolean).
  • To read the latest form values, call getFormData() (for example on submit).
  • If your code relied on v-model two-way binding previously, migrate to using a ref and the methods above.

This change avoids high-frequency two-way synchronization and improves performance for complex forms.

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
TREETree
SLIDERSlider
RATERate

Methods

MethodDescriptionType
validateValidate formFunction
validateFieldValidate specified fieldsFunction
clearValidateClear validationFunction
resetFieldsReset form (reset to initial data)Function
getFormDataGet form data (call on demand)Function
setFormDataSet form data (auto clear validation, support merge or replace)Function

Slots

NameDescriptionParameters
[prop]Custom form item content{ item: FormItemConfig, value: any, formData: Record }
label-[prop]Custom form item label{ item: FormItemConfig }

Released under the MIT License