Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unifying client- and server-side validation #125

Closed
alexweissman opened this issue Sep 23, 2014 · 1 comment
Closed

Unifying client- and server-side validation #125

alexweissman opened this issue Sep 23, 2014 · 1 comment
Labels
core feature request Feature request

Comments

@alexweissman
Copy link
Member

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:

{
    "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'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.

@alexweissman
Copy link
Member Author

This is all handled now by Fortress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core feature request Feature request
Projects
None yet
Development

No branches or pull requests

1 participant