Class FormValidatorBuilder<V, Err>

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.

Example

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()

Type Parameters

  • V extends object

  • Err

Hierarchy

  • FormValidatorBuilder

Constructors

Properties

Methods

Constructors

  • 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.

    Type Parameters

    • V extends object

    • Err

    Parameters

    Returns FormValidatorBuilder<V, Err>

    Example

    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()

Properties

fieldValidators: FieldValidator<any, Err, any>[]
schema: FormSchema<V, Err>
validate: ValidateFn<V, Err> = ...

Methods

Generated using TypeDoc