Custom Validation Rules
For multi-value validation, the Form
component's validators
prop provides comprehensive functionality to implement custom validation. For single-value validation, the Field
component contains 7 built-in common rules, please refer to its rule
prop. If those cannot meet your requirements, the VEUI
validation rule module allows you to add custom rules.
Examples
import ruleManager from 'veui/managers/rule'
ruleManager.addRule('range', {
validate (value, ruleValue) {
// Only implement the range comparison part
let range = value.split('-')
return +range[0] >= ruleValue.floor && +range[1] <= ruleValue.ceil
},
message: 'The range value must be within the specified range.',
priority: 100
})
<template>
<veui-field
:rules="[{
triggers: 'change'
name: 'range',
value: {
ceil: 100,
floor: 50
}
}]"
...
>...</veui-field>
</template>
API
Name | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
validate | function(value: *, ruleValue: ?*=) | The validation logic. value is the value that the Field needs to validate, and ruleValue is optional and is added according to the rule, representing the limiting value of the rule. | ||||||||||||||||||||||||
message | function | string | The default error message. If the type is
If the type is
| ||||||||||||||||||||||||
priority | number | The priority of the rule. Lower values have higher priority.
|