Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React redux Form checkbox `defaultChecked` not working

<Field
   defaultChecked={ true }
   onChange={ this.handleFormItemRadio }
   component={ "input" }
   type={ "checkbox" }
   name="tAdmin"
/>

When the field is initialized, I expect it to be checked but it renders unchecked even though I am supplying a true value.

I was pointed to number of solutions but am still not able to solve this.

like image 976
Mbanda Avatar asked Jun 17 '26 12:06

Mbanda


1 Answers

According to the docs, the prescribed way is to set initialValues

<Field
   onChange={this.handleFormItemRadio}
   component="input"
   type="checkbox"
   name="tAdmin"
/>

...

export default reduxForm({
  form: 'simple', // a unique identifier for this form
  initialValues: { tadmin: true },
})(SimpleForm);

Here's a CodeSandbox example

like image 107
Mrchief Avatar answered Jun 19 '26 03:06

Mrchief



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!