This repository was archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
draft
Ernest edited this page May 2, 2020
·
2 revisions
The following is all configs(and its default values).
FormValidation.config({
validateOnBound: false,
validateOnUpdated: true
})You can use second parameter to set Schema-scoped config.
FormValidation.createSchema({}, {
config: {
validateOnBound: false,
validateOnUpdated: true
}
})You can even override global config for any partial schema.
FormValidation.createSchema({
$config: {
validateOnBound: false,
validateOnUpdated: true
}
})$if: If
type Param = { value?: any, key?: string, path?: Array<string>, target?: any, params?: Object }
type If = ({ value, key, path, target, params }: Param) => booleanFor example, this feature would be useful for dynamic validation.
const form1 = {
ip: [
'8.8.8.8'
]
}
const form2 = {
ip: '8.8.8.8'
}
const schema = FormValidation.createSchema({
ip: [
{
// if
$if: ({ value }) => Array.isArray(value),
$rule: minLength(1),
$iter: {
$rule: ipAddress
}
},
{
// else if
$if: ({ value }) => typeof value === 'string',
$rule: ipAddress
},
{
// else
$rule: alwaysError
}
]
})