You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The goal is to create a unified way of representing form validation rules for both client- and server-side validation. The idea is to have a single JSON file for each form, called a schema. A schema simply maps each field to the validation rules for that field. For example:
{
"user_name" : {
"validators" : {
"length" : {
"min" : 1,
"max" : 50,
"message" : "'Username' must be between 1 and 50 characters long."
},
"required" : {
"message" : "'Username' is required."
}
}
},
"display_name" : {
"validators" : {
"length" : {
"min" : 1,
"max" : 50,
"message" : "'Display name' must be between 1 and 50 characters long."
},
"required" : {
"message" : "'Display name' is required."
}
}
},
...
I've written a class called ValidationSchema that can load this file, and generate the client- and server-side rules.
For the client-side rules, we'll be using bootstrapvalidator. The nice thing about this plugin is that you can specify all the rules in data-* attributes, so we can generate everything in FormBuilder.
For server-side rules, we'll continue with the valitron library. It doesn't have as active of a community as I'd like, but it is lightweight and can validate collections of fields (i.e. forms) as opposed to just individual variables.
I'll try to have server-side functionality, along with some documentation for the schema, up in the next few days. This should dramatically simplify our validation layer going forward.
The text was updated successfully, but these errors were encountered:
Just a sneak preview of what I'm up to.
The goal is to create a unified way of representing form validation rules for both client- and server-side validation. The idea is to have a single JSON file for each form, called a schema. A schema simply maps each field to the validation rules for that field. For example:
I've written a class called
ValidationSchema
that can load this file, and generate the client- and server-side rules.For the client-side rules, we'll be using bootstrapvalidator. The nice thing about this plugin is that you can specify all the rules in
data-*
attributes, so we can generate everything inFormBuilder
.For server-side rules, we'll continue with the valitron library. It doesn't have as active of a community as I'd like, but it is lightweight and can validate collections of fields (i.e. forms) as opposed to just individual variables.
I've already added the client-side functionality to bootsole; you can check it out here:
https://github.com/alexweissman/bootsole#validation-schema-and-validation-rules
I'll try to have server-side functionality, along with some documentation for the schema, up in the next few days. This should dramatically simplify our validation layer going forward.
The text was updated successfully, but these errors were encountered: