Skip to content

Conversation

@colinskow
Copy link
Contributor

Enable validation of deeply nested properties

Use a string with dot notation or bracket notation to perform validations on complex objects.

   var attributes = {
      name: "Nicklas Ansman",
      email: "[email protected]",
      deeply: {
        nested: {
          variable: "hello"
        }
      }
    };
    var constraints = {
      name: {
        pass: true
      },
      email: {
        pass: true,
        fail: true,
        fail2: true
      },
      "deeply.nested.variable": {
        fail2: true
      }
    };

    expect(validate(attributes, constraints)).toEqual({
      email: [
        "Email must be a valid email address",
        "Email is simply not good enough"
      ],
      "deeply.nested.variable": [
        "Deeply.nested.variable is simply not good enough"
      ]
    });

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 7f6e9ee on colinskow:nested into 07b3ecc on wrapp:master.

@colinskow colinskow mentioned this pull request Jul 7, 2014
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, tests for utility functions too! :)

@ansman
Copy link
Contributor

ansman commented Jul 13, 2014

Nice work! Thanks a bunch for this.

I'll attribute you in the docs and perhaps release this after I implement support for escaping . and adding some more tests.

ansman added a commit that referenced this pull request Jul 13, 2014
Validate deeply nested properties
@ansman ansman merged commit dd44721 into wrapp-archive:master Jul 13, 2014
@colinskow
Copy link
Contributor Author

Awesome! Now how do I force NPM to serve me the latest commit?

Ahh, in package.json... "validate.js": "https://github.com/wrapp/validate.js/tarball/062d5c2933"

@ansman
Copy link
Contributor

ansman commented Jul 15, 2014

{
  "dependencies": {
    "validate.js": "https://github.com/wrapp/validate.js.git#062d5c2933e5647fd100949ce8edbaf2db4418bf"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants