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

Validator Composability #566

Merged
merged 4 commits into from
Feb 13, 2018
Merged

Validator Composability #566

merged 4 commits into from
Feb 13, 2018

Conversation

offirgolan
Copy link
Collaborator

Easily compose complicated validations by using this this.test to validate
against pre-existing validators.

validate(value, options, ...args) {
  let result = this.test('presence', value, { presence: true }, ...args);

  if (!result.isValid) {
    return result.message;
  }

  result = this.test('number', value, { integer: true }, ...args);

  // You can easily override the error message by returning your own.
  if (!result.isValid) {
      return 'This value must be an integer!';
    }

  // Add custom logic...

  return true;
}

Tasks:

  • Added test case(s)
  • Updated documentation

@offirgolan offirgolan merged commit cfe88a4 into master Feb 13, 2018
@offirgolan offirgolan deleted the call-validator branch February 13, 2018 17:39
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.

1 participant