-
-
Notifications
You must be signed in to change notification settings - Fork 163
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow null default value while enforcing required validation #556
Labels
enhancement
New feature or request
Comments
Hi 馃憢馃徏 this will be possible soon once #502 is merged. Until then, you can use the following workaround: import * as v from 'valibot';
const FormSchema = v.object({
name: v.string(),
role: v.nullable(
v.object({
id: v.string(),
name: v.string(),
}),
{ id: '', name: '' }
),
secondaryRole: v.nullable(
v.object({
id: v.string(),
name: v.string(),
})
),
});
type FormInput = v.Input<typeof FormSchema>;
type FormOutput = v.Output<typeof FormSchema>; |
#502 is merged 馃殌 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! 馃憢
I'm using
valibot
withreact-hook-form
, and I need one of my properties to be required but with a default value of null. When the form is submitted and the value is still null, it should not validate.So far, I've managed this by creating a derived type from the output schema. However, I'm wondering if there's a more efficient way to handle this scenario?
I've added a simplified example of my scenario. The role selection isn't a typical input (here it's a clickable div, in my actual scenario it's a custom component).
Thank you!
The text was updated successfully, but these errors were encountered: