I want to save the radio button value to a state.
I have a form of a text box and few radio buttons. i want to save the text field and radio button value so that i can render these values in a table.
export class AddColumns extends React.Component{
constructor(props) {
super(props);
this.state={
newItemInput: '',
selectedValue: '',
buyItems :['Development','Testing']
}
}
handleChange(value) {
this.setState({
...state,
selectedValue: this.state.selectedValue
});
};
change (event){
this.setState({
[event.target.name]:event.target.value
});
console.log("button clicked",this.state);
};
render(){
return(
<div className="container">
<div className="form-group">
<label className="sr-only" htmlFor="newItemInput">Add New Item</label>
<input type ="text" ref ={input => this.newColumn = input} name="newItemInput" placeholder="Modules" value = {this.state.newItemInput} className="form-control"
id="newItemInput" onChange={event => this.change(event)}/>
</div>
<div className="k-form-field" value={this.state.selectedValue} onChange={this.handleChange}>
<input type="radio" name="radio" id="radio1" className="k-radio" />
<label className="k-radio-label">RadioButton 1</label>
<input type="radio" name="radio" id="radio2" className="k-radio" />
<label className="k-radio-label">RadioButton 2</label>
<input type="radio" name="radio" id="radio3" className="k-radio" />
<label className="k-radio-label">RadioButton 3</label>
</div>
<div className="form-group">
<button type="submit" className="btn btn-primary">Add</button><p>{this.state.messgae}</p>
</div>
</div>
);
}
I am not able to get the radio button value, please help