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

Using optionality and asynchronous rules in the same chain #206

Closed
usernamus opened this issue Oct 1, 2021 · 6 comments · Fixed by #223 or #227
Closed

Using optionality and asynchronous rules in the same chain #206

usernamus opened this issue Oct 1, 2021 · 6 comments · Fixed by #223 or #227

Comments

@usernamus
Copy link

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?

@sbarfurth sbarfurth added this to the v1.5.0 milestone Feb 13, 2022
@sbarfurth
Copy link
Collaborator

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.

@sbarfurth sbarfurth mentioned this issue Feb 18, 2022
6 tasks
@sbarfurth
Copy link
Collaborator

So @usernamus, I've created #223. Is that what you were looking for?

@usernamus
Copy link
Author

Wow. Thank you. This really seems to be what I need.

@sbarfurth
Copy link
Collaborator

Alright, barring review we can target this for the next release (which will be 1.5.0).

@sbarfurth
Copy link
Collaborator

sbarfurth commented Mar 13, 2022

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.

@usernamus
Copy link
Author

@barfurth oh, that sounds great. Thanks you so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants