another-form-validator
v0.1.5
Published
A framework agnostic, customizable form validator
Downloads
5
Readme
Another Form Validator
A framework agnostic, customizable form validator
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