Create form validator based on provided set of validation rules.
Error type of all validation rules must be first defined using FormSchemaBuilder.
Behaviour of individual field validators can be further configured
by specifying dependencies, triggers or debounce options.
const validator = new FormValidatorBuilder(Schema)
.validate(
Schema.password,
required("password is required!"),
minLength(6, "password must be at least 6 characters long!")
)
.validate({
field: Schema.passwordConfirm,
dependencies: [Schema.password],
triggers: ["blur", "submit"],
rules: (password) => [
required("password confirmation is required!"),
val => val === password ? null : "passwords are different",
]
})
.validate(
Schema.promoCodes.every(),
optional(),
exactLength(6, "promo code must be 6 characters long")
)
.build()
Private Readonly fieldPrivate Readonly schemaPrivate buildGenerated using TypeDoc
Create form validator based on provided set of validation rules. Error type of all validation rules must be first defined using
FormSchemaBuilder. Behaviour of individual field validators can be further configured by specifyingdependencies,triggersordebounceoptions.Example