Closed g-kduvignau closed 5 months ago
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>;
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!