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

[Feature Request] Validations on a nested object. #9

Closed
pselden opened this issue Nov 20, 2014 · 4 comments
Closed

[Feature Request] Validations on a nested object. #9

pselden opened this issue Nov 20, 2014 · 4 comments

Comments

@pselden
Copy link

pselden commented Nov 20, 2014

Is it possible to run validations on a nested object?

For instance.

var paymentInfo = {
   creditCard: {
     number: 45343434343,
     expiration: '01/15'
   }
};

var validator = LGTM.validator()
   .validates('creditCard.number').required('Credit card number is required')
.build();

validator.validate(paymentInfo).then(function() {/*... */);

If not, is there a way to do something like this or do I have to build validations for each part separately and combine the results?

@pselden
Copy link
Author

pselden commented Nov 20, 2014

Re the combining part -- something like this maybe would be a nice api?

var creditCardValidator = LGTM.validator()
  .validates('number').required('You must enter a card number')
  .validates('expiration').required('Expiration is required')
.build();

var paymentInfoValidator = LGTM
.validator()
  .validates('creditCard').using(creditCardValidator)
.build();

How to merge the two results together would be an interesting challenge though.

@pselden pselden changed the title Validations on a nested object. [Feature Request] Validations on a nested object. Nov 20, 2014
@eventualbuddha
Copy link
Contributor

This is an area LGTM could definitely improve. Most commonly at Square the problem that LGTM doesn't solve well is validating repeated child properties, i.e. children whose values are lists of things. How do you think you'd solve such a case?

@eventualbuddha
Copy link
Contributor

Closing as inactive.

@ianwalter
Copy link

@pselden Did you find a work around for this? Your second example looks ideal.

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

No branches or pull requests

3 participants