How to conditionally require a field? #297
-
Hi, I have a field that should be required conditionally, depending on a checkbox outside of the form. How can I implement that with Valibot?
|
Beta Was this translation helpful? Give feedback.
Answered by
fabian-hiller
Dec 15, 2023
Replies: 1 comment 8 replies
-
There are several solutions. To make it type safe, I recommend using a discriminated union with |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recommend to write the following.
union
has nopipe
argument yet, that's why I added the validation toobject
and forwarded the error toname
. I plan to improve that.