another-form-validator
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

Another Form Validator

A framework agnostic, customizable form validator

NPM Version

Install

npm install another-form-validator

Usage

import FormValidator from 'another-form-validator'

let model = {
    pineapple: 1
}

const formValidator = new FormValidator()

formValidator.registerField({
    name: 'pineapple',
    model: () => model.pineapple,
    validators: [{
        getError: () => 'multiple pineapples are required',
        validate: (value) => value > 1
    }],
    onChange: [
        (field) => {
            // called on field events (touch, dirty, validate)
            if (field.errors.length) {
                const errorToDisplay = field.errors[0]
            }
        }
    ]
})

model.pineapple = 2

formValidator.touch('pineapple')
formValidator.dirty('pineapple')

const formIsValid = formValidator.validate()
console.log(formIsValid) // true

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i another-form-validator

Weekly Downloads

0

Version

0.1.5

License

MIT

Unpacked Size

210 kB

Total Files

21

Last publish

Collaborators

  • adwhitaker