RedwoodJS supplies many types of fields for forms, including a CheckboxField
for emitting a..well...checkbox field.
I recently added a CheckboxField
to a form for my training journal, and had some trouble setting a default value on it.
Turns out I had the prop name incorrect. I expected it to be defaultValue
like other form components, but the correct prop is defaultChecked
:
<CheckboxField
name="isKeyWorkout"
className="rw-input"
errorClassName="rw-input rw-input-error"
defaultChecked={props.planWorkout?.isKeyWorkout}
/>
I tracked this down by looking for the original implementation of that component, and finding a test that demonstrated the proper way to set a default value.
I couldn't find this in the docs anywhere, so maybe this will help you one day when searching for "redwoodjs checkboxfield default".