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>
)
})}
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 .
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.
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}/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With