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

Async support #53

Merged
merged 1 commit into from
Jun 23, 2015
Merged

Async support #53

merged 1 commit into from
Jun 23, 2015

Conversation

garygreen
Copy link
Collaborator

With this PR it adds asynchronous validation support:

Validator.registerAsync('username', function(value, ruleValue, attribute, passes) {
  // check from database etc then call...
  passes();
  // or fail with custom error
  passes(false, 'Username is banned');
}, ':attribute field is invalid');

It also refactors rules, .validate is no longer accessible, you need to access rules by Validator.getRule(<name>) which exposes some functions like .validate()

@garygreen garygreen mentioned this pull request Jun 15, 2015
@garygreen garygreen force-pushed the async branch 2 times, most recently from 0ba5724 to a053f3e Compare June 21, 2015 22:04
@garygreen
Copy link
Collaborator Author

@skaterdav85 I've got it all working now, lots of tests and all passing. The implementation could be tweaked a bit but if your happy with it / any suggestions let me know :-)

Btw I decided to go with the one callback passes as having two is a bit redundant and unnecessary. You could name this however you like in your app e.g. response(true) response(false, 'Custom error').

In any case we can work a few things out or tweak them before releasing 2.0.

@garygreen
Copy link
Collaborator Author

@skaterdav85 Have you had chance to take a look? :)

iamdtang pushed a commit that referenced this pull request Jun 23, 2015
@iamdtang iamdtang merged commit d6223af into master Jun 23, 2015
@iamdtang
Copy link
Collaborator

awesome work @garygreen!

@garygreen garygreen deleted the async branch June 23, 2015 17:53
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.

None yet

2 participants