Using optionality and asynchronous rules in the same chain
usernamus opened this issue · 6 comments
I would like to be able to write something like this chain of validations:
v8n().optional(v8n().email().checkEmailAvailable())
email
– regular rule for email validation (pattern)
checkEmailAvailable
– async rule
But right now it's not possible because inside optional rule we use .check
strategy.
Is there a chance that this behavior can be implemented?
This should actually be fairly easy, it would probably require either an additional rule (asyncOptional
?) or a parameter to the optional
rule. Maybe there is a better solution than either of these, but those seem like the logical ones. @imbrn ?
Generally speaking this idea makes sense and should be implemented. Considering it's a new feature this one can be in 1.5.0.
So @usernamus, I've created #223. Is that what you were looking for?
Wow. Thank you. This really seems to be what I need.
Alright, barring review we can target this for the next release (which will be 1.5.0).
Just FYI @usernamus, the next release will still contain this feature but it will be slightly different than #223 had it. The asynchronous validation will simply be supported on the optional
rule when the testAsync
strategy is used. This should be even simpler than adding a new rule. See #227.
@barfurth oh, that sounds great. Thanks you so much