Default Value with booleans + checkboxes doesnt work #343
-
Describe the bug and the expected behaviorUnless Im doing something wrong I cant seem to get default values to play nicely with checkbox inputs (when they are meant to represent boolean schemas) See the code below but if a schema contains a boolean property Any help is appreciated if Im doing something wrong. Thanks! Conform versionv0.9.1 Steps to Reproduce the Bug or IssueI grabbed this example from the docs verbatim, but added a defaultValue to the useForm config:
Render the above form. I'd expect to see "Terms and conditions" checked on page load. What browsers are you seeing the problem on?Chrome Screenshots or VideosNo response Additional contextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Try this: const [form, { acceptTerms, subscribeNewsletter }] = useForm({
onValidate({ formData }) {
return parse(formData, { schema });
},
defaultValue: {
// `on` is the default value of the checkbox unless you specified it on the element
acceptTerms: 'on',
},
}); There are some limitations on the current implementation on how default value are handled and you need to think in terms of the input value ( Is you project setup with Typescript? I expect it to complain when you pass |
Beta Was this translation helpful? Give feedback.
Try this:
There are some limitations on the current implementation on how default value are handled and you need to think in terms of the input value (
on
for checkbox / radio button). What you did would work when v1 is released.Is you project setup with Typescript? I expect it to complain when you pass
true
as well.