Skip to content

DyFormItem

DyFormItem is the configuration type for a single field in a dynamic form. You pass an items array into NaiDynamicForm, and each element in that array is a DyFormItem.

SelectOptionItem

FieldDescriptionTypeDefaultRequired
labelDisplay textstringYes
valueOption valueanyYes
classCustom classstringNo
styleCustom stylestring | CSSPropertiesNo
disabledWhether disabledbooleanNo

BaseDyFormItem

FieldDescriptionTypeDefaultRequired
keyField identifier (recommended to match the form model field)keyof TYes
labelForm item labelstringNo
valueReactive value (form data source)Ref<any>; if wrapped by useReactiveForm or useDecorateForm, you can omit ref (it will be wrapped automatically)Yes
placeholderPlaceholder textstringNo
optionsOptions data (for select/checkbox/radio, etc.)SelectOptionItem[] | any[]No
onChangeValue change callback(value: any, associationItem: DyFormItem, options?: SelectOptionItem[] | any[]) => voidNo
spanGrid span (commonly used when preset="grid")numberNo
offsetGrid offset (commonly used when preset="grid")numberNo
sortSort key (if sorting logic is enabled, items are sorted by this field)numberNo

DyFormItem

DyFormItem<K, RuleT> extends BaseDyFormItem<K> and adds rendering, validation, and display-control capabilities.

FieldDescriptionTypeDefaultRequired
pathValidation path (defaults to key if not provided)stringNo
hiddenWhether to hide this itembooleanfalseNo
render2Custom render function (returns a VNode)(formItem: DyFormItem) => VNodeNo
resetCustom reset logic(formItem: DyFormItem) => voidNo
ruleField validation rule (type depends on the UI layer, e.g., Naive UI’s FormItemRule)RuleTNo
requiredShorthand required flag (if rule is not provided, a required rule can be generated automatically)booleanfalseNo
requiredHintRequired-field message generator(label: string) => string"label" cannot be emptyNo
disabledDisabled state (supports boolean or Ref<boolean>)boolean | Ref<boolean>falseNo
clearableWhether clearing is allowedbooleanfalseNo
typeShorthand input type (commonly used for input)"text" | "textarea" | "password""text"No
rowsNumber of rows for multiline input (commonly used with type="textarea")numberNo
labelFieldMapping for the label field name in optionsstringNo
valueFieldMapping for the value field name in optionsstringNo
filterableWhether filtering is enabled (commonly used for select-like components)booleanfalseNo
multipleWhether multiple selection is enabled (commonly used for select-like components)booleanfalseNo

about RuleT

DyFormItem uses the generic RuleT for its rule field to avoid binding the shared type definitions to a specific UI framework. For example, in the Naive UI module, you can bind RuleT to FormItemRule \| FormItemRule[].