aurelia / validatejs

Enables expressive validation using decorators and/or a fluent API.
MIT License
22 stars 23 forks source link

Add custom validation rule support #4

Closed plwalters closed 8 years ago

plwalters commented 8 years ago

https://validatejs.org/#custom-validator

Add decorator / fluent API to cover.

apawsey commented 8 years ago

Has any progress been made on this? Is there a structure that is being proposed?

Quick suggestion would be something in the plugin config that dynamically adds properties to the current validator object, to provide the same api approach with custom validators as built-in ones. Alternatively, a validators.custom property, that we then extend, if it's preferred to have some kind of division?

I assume the custom validators would need to be configured in the DI somehow, as for example the api lookup type validator mentioned in #29 would need httpClient injected in.

plwalters commented 8 years ago

No progress on this one yet PR welcome. Under the covers the ValidationRule class should probably just have a static method for adding the custom rule that works just like the current rule methods work.

aivins commented 8 years ago

@PWKad - I ended up hacking this together for myself today but I'm not sure I took the right approach. validate.async returns a promise, whereas aurelia-validatejs seems to strongly assume the opposite. I ended up converting all validate return values into promises, then using Promise.all() to wait on them all at once before returning to the original caller. I also publish each error into the reporter when Promise.all() resolves.

I also had to patch validate.js's async so that it doesn't reject if an async function returns an error. That was stopping me from handling it later on with Promise.all().

RWOverdijk commented 8 years ago

👍 I'd like to provide a custom validator with my plugin :)

@PWKad I'm fine with working on this. I need some pointers though, how can this be done?

jdanyow commented 8 years ago

implemented!