nf-form
An Element Plus Form wrapper preserving validation and field APIs with expandable query fields.
Import the components below; see the package README for standalone installation.
Expand and collapse form fields
Loading example…
Expand and collapse form fields
Dynamic form fields
Loading example…
Dynamic form fields
Attribute
| parameters | Description | Type | Optional value | Default value |
|---|---|---|---|---|
| model | form data object | object | — | — |
| rules | form validation rules | object | — | — |
| inline | Inline form mode | boolean | — | false |
| label-position | The position of the form field label. If the value is left or right, label-width needs to be set. | string | right/left/top | right |
| label-width | The width of the form field label, for example '50px'. Form-item elements that are direct children of Form inherit this value. Support auto. | string | — | — |
| label-suffix | Suffix for form field labels | string | — | — |
| hide-required-asterisk | Whether to hide the red asterisk next to the label of a required field | boolean | — | false |
| show-message | Whether to display verification error information | boolean | — | true |
| inline-message | Whether to display verification information inline | boolean | — | false |
| status-icon | Whether to display the verification result feedback icon in the input box | boolean | — | false |
| validate-on-rule-change | Whether to trigger a verification immediately after the rules attribute changes | boolean | — | true |
| size | Control the size of components in the form; compatible with mini→small, medium→default. | string | medium/small/mini | undefined |
| disabled | Whether to disable all components within this form. If set to true, the disabled attribute on components within the form will no longer take effect. | boolean | — | false |
| showBtn | Whether to enable the fold button function | boolean | — | true |
| columns | Fold when exceeding the specified number; retain the first columns-1 participants and the last operation item when folding. | number | — | 3 |
| upIcon | Collapse button icon class name; defaults to built-in SVG. | string | — | 'icon-xiangshang2' |
| downIcon | Expand button icon class name; uses built-in SVG by default. | string | — | 'icon-xiangxia2' |
| isCollapse | Initialize whether to fold | boolean | — | true |
| expandBtnType | Expand button type | string | primary/success/warning/danger/info/text/default | '' |
| expandBtnIcon | Expand button icon | string | — | undefined |
| expandBtnPlain | Expand button plain | boolean | — | true |
| expandBtnSize | Expand button size, the default is based on the form size. It is worth noting that after setting this, if it is not a value in the enumeration, it will be regarded as the default size of the button (the default maximum size, equivalent to large) | string | medium/small/mini | undefined |
| expandBtnRound | Expand button round | boolean | — | false |
| expandBtnCircle | Expand buttoncircle | boolean | — | false |
| expandBtnLoading | Expand button loading | boolean | — | false |
| expandBtnDisabled | Expand buttondisabled | boolean | — | false |
| expandBtnTooltipDesc | Expand button tooltip text. | string | — | Follow language pack |
| shrinkBtnTooltipDesc | Collapse button text. | string | — | Follow language pack |
Methods
| method name | Description | parameters |
|---|---|---|
| validate | A method for validating the entire form. The parameter is a callback function. This callback function will be called after the verification is completed, and two parameters will be passed in: whether the verification was successful and the fields that failed the verification. If no callback function is passed in, a promise will be returned | Function(callback: Function(boolean, object)) |
| validateField | How to verify some form fields | Function(props: array |
| resetFields | Reset the entire form, reset all field values to their initial values and remove validation results | — |
| clearValidate | Remove the validation results from the form item. Pass in the prop attribute or array of props of the form item to be removed. If not passed, the verification result of the entire form will be removed. | Function(props: array |
| scrollToField(prop) | Scroll to the specified field. | string |
| getField(prop) | Get field context. | string |
| getFormItems() | Refresh dynamic form item order. | — |
Event
| event name | Description | callback parameters |
|---|---|---|
| validate | Triggered after any form item is verified | The form item being validated prop Value, whether the verification passed, error message (if present) |
| isCollapseChange | Triggered by change of form expansion state, true means expansion. | expanded: boolean |
Slot
| Name | Description |
|---|---|
| default | Form content; use NfFormItem to register the collapse item. |
nf-form-item Attribute
| parameters | Description | Type | Optional value | Default value |
|---|---|---|---|---|
| hidden | Controls whether the form item participates in the hidden drop-down function, true does not participate | boolean | — | false |
| prop | Form field model field, this attribute is required when using the validate and resetFields methods. | string | incoming Form component model fields in | — |
| label | label text | string | — | — |
| label-width | The width of the form field label, for example '50px'. 'auto' is supported. | string | — | — |
| required | Is it required? If not set, it will be automatically generated based on the verification rules. | boolean | — | false |
| rules | form validation rule | object | — | — |
| error | Form field validation error message. Setting this value will change the form validation status to error and display the error message. | string | — | — |
| show-message | Whether to display verification error information | boolean | — | true |
| inline-message | Display verification information inline | boolean | — | false |
| size | Used to control the size of components under this form field | string | medium/small/mini | - |
nf-form-item Slot
| Name | Description |
|---|---|
| default | Contents of Form Item |
| label | The content of the label text |
nf-form-item Scoped Slot
| Name | Description |
|---|---|
| error | Customize the display mode of form verification information, the parameter is |
nf-form-item Methods
| method name | Description | parameters |
|---|---|---|
| resetField | Reset the form item, reset its value to its initial value and remove the verification result | - |
| clearValidate | Remove the verification result of this form item | - |
Instructions for use
The hidden of NfFormItem means that it does not participate in folding and remains on the page. Validation, reset, and field methods use Element Plus's public API; do not rely on Vue 2 private instances.
