Skip to content

Form

Basic Usage

  • iForm can be used for querying or submitting data.
  • The default mode is querying. In querying mode, Form displays two rows by default and other items hidden.
  • the configuration of iForm is controlled by formOpts, which is a object. It includes the configuration of each form item, form layout etc. Use v-model to bind the data of the form.
  • colSize prop can control the number of item in one row.
  • handleSeach and handleReset events are triggered when the search button and reset button are clicked respectively.

Submit Form

  • you can set formType = 'edit' to switch form to submit mode.
  • in submit mode, the query and reset buttons are disappeared. You can use v-model to bind the data of the form. The submit button should be implemented by developers themselves.
  • the form can also be submitted by pressing the Enter key. In this case, the handleSubmit event is triggered.

Select Options from API

Sometimes, the options of the select component are not static, but need to be fetched from the API. In this case, you can configure options attribute in fieldList prop as a string identifer. Then assign data retrieved from request to the coresponding array value, whose key is the same as aforementioned identifer in externalOptions

Validation

  • Configure rules attribute in formOpts prop to set the validation rules of the form.
  • The validation rules are the same as the rules of the Element Plus form component.
  • the exposed function formValidate can trigger the form validation and return the validation result.

Custom Form Item

If you need to use a custom component as a form item, you can set slotName attribute in the item in fieldList prop to the name of the custom component.

API

Attributes

iForm

Nameis RequiredDescriptionTypeDefault Value
classNameNocss class namestring-
v-modelNodata of formObject{}
formTypeNotype of form (search/sumbit)stringsearch
formOptsYesform configurationObject-
colSizeNonumber of items in one row, max: 6Number-

iForm is a secondary encapuslation base on Form from Element plus. For description of other properties, please refer to Form

formOpts

Nameis RequiredDescriptionTypeDefault Value
labelWidthNowidth of labelstring'120px'
defaultFormNodefault data of formObject{}
fieldListYesconfiguration of form itemsArray-
sizeNosize of formstring'default'
rulesNoform rules, the same as el-form rulesObject{}
labelPositionNothe position of label('left'/'right'/'top'), if set 'left' or right, the labelWidth prop is also requiredstring'right'
externalOptionsNodynamic options dict, it is valid when option prop in fieldList is set as a string identifierObject{}

fieldList

Nameis RequiredDescriptionTypeDefault Value
labelYeslabel teststring-
valueYeskey to the form datastring-
disabledNowhether the filed is disabled or notBooelanfalse
typeNotype of form item string''
compYescomponent of form item(el-input, el-select, etc)string-
optionsNoselect option of form item, it is required when comp is 'el-select', 'el-checkbox-group' or 'el-radio-group'Array/String-
textShowNowhether form item displays as plain textBooleanfalse
labelRenderNowhether to custmize the label or notBooleanfalse
placeholderNoinput hintstring-

Event

NameDescriptionParameters
handleSearchin query mode,trigger when query buttion is clickedformData: Object
handleResetin query mode, trigger when reset button is clicked-
handleSubmitin edit mode, triggeer when enter key is pressedformData: Object

Exposes

NameDescriptionParameters
formValidateverify form-
resetFieldsreset form-
clearValidateclear form validation-