Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncheck radio buttons in react

I think its a very silly doubt but I am stuck in this.. I have multiple radio buttons and I want to uncheck all the radio buttons as soon as I click the other radio button. How can I achieve it in react?

var options = [{id:1,nm:"Appointment fixed"},{id:2,nm:"Call later"},{id:3,nm:"Wrong number"},{id:4,nm:"Don't call again"},{id:5,nm:"Call later"}];
{options.map((item,i) => {
                     return (
                        <div onChange={(i)=>this.callOptions(i)}>
                           <label className="radio-inline"><input type="radio" value={i} ref={'ref_' + i} value={item.id}/>{item.nm}</label>
                        </div>
                      )
                  })}
like image 210
Saif Ali Khan Avatar asked Jun 01 '17 21:06

Saif Ali Khan


People also ask

How do I uncheck a radio button?

To set a radio button to checked/unchecked, select the element and set its checked property to true or false , e.g. myRadio. checked = true .

How do I reset the radio button in React?

To reset radio buttons in React on click of a Reset button, we set empty string '' or null value to the radio state gender on click of the button. Pass the resetRadioState function to the onClick event handler.


1 Answers

Give a common name attribute for you radio button. Change

<input type="radio" value={i} ref={'ref_' + i} value={item.id}/>

to

<input type="radio" value={i} name="abc" ref={'ref_' + i} value={item.id}/>

like image 83
Suresh Prajapati Avatar answered Sep 20 '22 12:09

Suresh Prajapati