Skip to content

v6: Looking for example to useFieldArray() and multiple checkboxes #398

Answered by airjp73
ZipBrandon asked this question in Q&A
Discussion options

You must be logged in to vote

Should work about the same as v5.

Set default value with an array of strings:

pizzaToppings: ["pepperoni", "mushroom"]

Then wire up some regular checkboxes.

const field = form.field("pizzaToppings"); // or useField or pass the name to getInputProps

// ...
<input {...field.getInputProps({ type: "checkbox", value: "pepperoni" })} />
<input {...field.getInputProps({ type: "checkbox", value: "mushroom" })} />
<input {...field.getInputProps({ type: "checkbox", value: "onion" })} />

Then when it comes to validation keep in mind that, if one checkbox is checked (assuming you're not using submitSource: state), the validator will receive a single string instead of an array of strings. Which you c…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ZipBrandon
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants