Skip to content

simfatic/boel

Repository files navigation

BoelJS

Form Data validation library

Note : Work in progress

Usage

let b = makeBoel();
const rules = [ 
    b.field('name').isRequired().minLength(5).maxLength(100),
    b.field('email').isEmail().isRequired(),
]

let res = b.validate(rules, formData)
if(res.has_errors){
    //res.error_map[field_ame].message contains the error message
    email_error = res.error_map.email.message
}

Validate conditionally

    b.field('age').isBetween(10,60).message("Age out of range").onlyWhen("paying_now==1"),

    /** Compare between fields */
    b.field('current_salary').isGreaterThan('prev_salary'),

Shortcut for validating multiple fields, same validations

/** multiple fields at the same time */
b.fields("name", "email").areRequired().maxLength(100);
// Fields name and email are required with maxlength 100 (for both fields)

Customize/Translate Error message templates

/** change/translate message templates for all validations */
b.updateMessages({
    'Required':"{{field}} is required", 
    "MaxLength":"The input shouldn't exceed {{max_length}} characters"
})

About

Form Data validation library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published