Validate

Control

Former allows you to write the verification information in JSON schema. All the rules will inject into UI library controls.

in Element UI, you need to maintain multiple copies of the data, and the verification rules are taken separately:

...
<el-form :model="model" :rules="rules">
</el-form>
...

but in Former, all in JSON schema:

{
  label: 'input',
  name: 'input',
  type: 'input',
  rules:[ { required: true, trigger: 'blur' } ]
}

Or some more complicated verification:

Global

Former has provided some functions to validate form fields:

Methods

Method Description Parameters
validate validate the whole form. Takes a callback as a param. After validation, the callback will be executed with two params: a boolean indicating if the validation has passed, and an object containing all fields that fail the validation. Returns a promise if callback is omitted Function(callback: Function(boolean, object))
validateField validate one or serveral form items Function(props: string)
resetFields reset all the fields and remove validation result -
clearValidate(Element UI) clear validation message for certain fields. The parameter is prop name or an array of prop names of the form items whose validation messages will be removed. When omitted, all fields' validation messages will be cleared Function(props: string)
Last Updated: 2/15/2019, 4:04:50 AM