question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

radio buttons are not working with react

See original GitHub issue

I render html using react like this:

var RegisterBox = React.createClass({
  clickOk:function(e) {
    e.preventDefault();
  },
  render:function(){
    return (
      <div className="row">
        <form className="col s12">
          <div className="row">
            <div className="input-field col s12">
              <input placeholder="input your nickname" id="nickname" type="text" className="validate" />
              <label for="nickname">input your nickname</label>
            </div>
          </div>
          <div className="row">
            <div className="input-field col s12">
              <input id="password1" type="password" className="validate" />
              <label for="password">set pwd</label>
            </div>
          </div>
          <div className="row">
            <div className="input-field col s12">
              <input id="password2" type="password" className="validate" />
              <label for="password">repeat pwd</label>
            </div>
          </div>
          <div className="row">
            <div className="col s6">
              <input name="contactm" type="radio" id="email1" value="email" defaultChecked />
              <label for="email">use email</label>
            </div>
            <div className="col s6">
              <input name="contactm" type="radio" id="tel" value="tel" />
              <label for="tel">use mobile</label>
            </div>
          </div>
          <div className="row">
            <div className="input-field col s12">
              <input id="email" type="email" className="validate" />
              <label for="email">Email</label>
            </div>
          </div>
          <div className="row">
            <button className="btn waves-effect waves-light" name="action" onClick={this.clickOk}>register
            </button>
          </div>
        </form>
      </div>
    )
  }
})

ReactDOM.render(
  <RegisterBox />,
  document.getElementById('content')
);

The radio buttons, however, are not working. When I click the other radio button, there is nothing happening.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
mparker11commented, Sep 28, 2017

This is super late. I stumbled upon this due to my own issues but I believe the problems with this was using for instead of htmlFor for the label attribute. for is not recognized in React.

0reactions
ghostcommented, Jun 15, 2016

did this ever got resolved? In my React app I have issues working with checkboxes and radio buttons. they get rendered well but never fire an event. because the input is never clicked.

<p>
  <input name='group1' value='value1' type='radio' id='test1' onChange={(e)=>{console.log(e.target);}}/>
  <label for='test1'>Red</label>
</p>
<p>
  <input name='group1' value='value2' type='radio' id='test2' onChange={(e)=>{console.log(e.target);}}/>
  <label for='test2'>Red2</label>
</p>
Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - Radio button not working - Stack Overflow
Warning: RadioButton contains an input of type radio with both checked and defaultChecked props. Input elements must be either controlled or ...
Read more >
How to work with radio buttons in React - DEV Community ‍ ‍
In this article, we will see how to render radio buttons in react and how to know which radio button is selected. First,...
Read more >
How to Use Radio Buttons in ReactJS | Pluralsight
Radio buttons let a user choose a single option from a list of multiple radio buttons and submit its value. · For example,...
Read more >
Radio Buttons In React.js
It's clear that our <input> component has 2 states to render: selected radio button and unselected radio button. Let's make our Application component...
Read more >
How to create a React Radio Button - Robin Wieruch
Follow on Facebook. A short React tutorial by example for beginners about using a radio button in React. First of all, a radio...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found