How do you validate a checkbox boolean in a valibot form schema? #247
-
Hi I'm really loving valibot so far, but I have run into a roadblock. The below code is from a Qwik project with modular forms installed. I've been following their documentation but they didn't include any examples for how to validate checkboxes (with the help of valibot), which left me in the dark. Here below is the code: const EmailSchema = object({
...
terms: boolean("You must agree to the terms of service before submitting an email.", [
//I want to check if the boolean value of the terms of service checkbox is equal to true.
//In other words, I want the checkbox to be required while still being of the
]),
});
type EmailForm = Input<typeof EmailSchema>;
export const useFormLoader = routeLoader$<InitialValues<EmailForm>>(() => {
return {
...
terms: false,
};
}); Based on having perused the documentation and looking at the code, I initially found I think fundamentally I have a misunderstanding here and I'm curious what the solution is to the goal I want to achieve😅. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks for the info. We should probably update const Schema = literal(true, 'Please accept our terms.'); |
Beta Was this translation helpful? Give feedback.
Thanks for the info. We should probably update
value
to support boolean as well. For now,literal
is the way to go. It keeps the bundle size to a minimum and does a straight check fortrue
.