mikeerickson / validatorjs

A data validation library in JavaScript for the browser and Node.js, inspired by Laravel's Validator.
https://www.npmjs.com/package/validatorjs
MIT License
1.77k stars 280 forks source link

Async validation run twice #155

Closed foxhound87 closed 7 years ago

foxhound87 commented 7 years ago

I call both .passes() and .fails() to check the async validation. Right now I don't find any solution to check both validation states without calling both of them. This runs the validation twice.

I think we need a method which runs the async function only one time and calls respectively passes/fails callbacks. Or at least a promise implementation (as I proposed in this issue: https://github.com/skaterdav85/validatorjs/issues/127)

For example a possible solution could be to provide a validation function which accept an object with the two callbacks:

validator.validate({
  passes: () => {},
  fails: () => {},
});

We discussed the problem in this issue: https://github.com/foxhound87/mobx-react-form/issues/214

Thank You.

garygreen commented 7 years ago

What about checkAsync ?

foxhound87 commented 7 years ago

Is it already available? I don't see it documented

foxhound87 commented 7 years ago

That's working. Thank You.

raghavgarg1257 commented 7 years ago

@foxhound87, Please can you share how did you overcome this problem using checkAsync. Any type of help is appreciated.

foxhound87 commented 7 years ago

@raghavgarg1257 take a look at this commit:

https://github.com/foxhound87/mobx-react-form/commit/b74be11f3d16af53870a55a9e5a26654dbff4b36

raghavgarg1257 commented 7 years ago

@foxhound87 Thanks, for the reply.

alisherafat01 commented 6 years ago

@foxhound87 Can you write a real example here? I have this issue and can't figure out how to resolve.