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

2
  • What version of redux-form are you using? Commented Feb 26, 2019 at 16:12
  • @Mrchief "redux-form": "^7.4.2" Commented Feb 27, 2019 at 6:48

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

2 Comments

Apparently this doest work for me. And to be little more inquiry, my form has several fields with dynamic true Or False (from props), i dont expect to supplie each field name to initialValues . There should be some way to streamline that
Post your full sample in that case. You probably will have to roll your own chechkbox field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.