Skip to content

Default Value with booleans + checkboxes doesnt work #343

Answered by edmundhung
andrewkucz asked this question in Q&A
Discussion options

You must be logged in to vote

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 (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.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@andrewkucz
Comment options

@adam1658
Comment options

@edmundhung
Comment options

Answer selected by andrewkucz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #342 on November 21, 2023 14:48.