1

On the bases of the value of radio button(html mention below) I want to mark checkbox as checked or unchecked. Below is my code which is not working.

Thank you for your suggestions.

Radio button

    <Input
      type="radio"
      name="radio1"
      value="No"
      defaultChecked
      onChange={ (e) => {
                         this.setState({
                                        auto_registration: e.target.value
                                       })
                        } } />
    <Input
      type="radio"
      name="radio1"
      value="Yes"
      onChange={ (e) => {
                         this.setState({
                                        auto_registration: e.target.value
                                       })
                        } } />

Checkbox

<Input
      type="checkbox"
      defaultChecked={ this.state.auto_registration && this.state.auto_registration == "Yes" ? true : false }
      disabled={ this.state.auto_registration && this.state.auto_registration == "Yes" ? true : false } />

1 Answer 1

3

defaultChecked property is only used on initial render. If you want to have a controlled checked input, se the checked property instead

<Input
      type="checkbox"
      checked={ this.state.auto_registration && this.state.auto_registration == "Yes" ? true : false }
      disabled={ this.state.auto_registration && this.state.auto_registration == "Yes" ? true : false } />
Sign up to request clarification or add additional context in comments.

Comments

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.