Replies: 1 comment
-
By optional, do you mean an empty string? Here is one solution. Try it out in this playground. import * as v from 'valibot';
const Schema = v.object({
foo: v.union([
v.literal(''),
v.pipe(
v.string(),
v.minLength(3, 'too short'),
v.maxLength(255, 'too long'),
),
]),
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want a field to be optional, but if someone enters something into the input, it must match some rules.
I got this schema:
This does not work. If I dont enter anything to "description", I still get the "too short" message.
What did I miss?
Beta Was this translation helpful? Give feedback.
All reactions