So I'm getting some data from backend which looks something like this
{"data":[{"status":1, "title":"Title 1"}, {"status":2, "title":"Title 2"}, {"status":1, "title":"Title 3"}, {"status":3, "title":"Title 4"}]}
They are to be mapped into a list where the value of status determines one of 3 radio buttons which I did like below
{data.map(d => {
return (
<ListGroupItem>
<Row>
{d.title}
<FormGroup>
<Input
type="radio"
name={d.title}
value="1"
checked={d.status === 1}
onChange={this.changeHandler}
/>
Open
</FormGroup>
<FormGroup check inline>
<Input
type="radio"
name={d.title}
value="2"
checked={d.status === 2}
onChange={this.changeHandler}
/>
In-progress
</FormGroup>
<FormGroup check inline>
<Input
type="radio"
name={d.title}
value="3"
checked={d.status === 3}
onChange={this.changeHandler}
/>
Closed
</FormGroup>
</Row>
</ListGroupItem>
);
})}
So my list would look something like
Title 1 * open 0 in-progress 0 closed
Title 2 0 open * in-progress 0 closed
Title 3 * open 0 in-progress 0 closed
Title 4 0 open 0 in-progress * closed
(not the best way to show this)
Now I need this in a form so that when submitted the selected value will updated data in the backend. How would I go about doing that? Also how will I handel the onChange event since right now even if I select a radio button nothing will change.
changeHandler = e => {
//map the data to the proper place
}
submitHandler = e => {
//submit the data
}
P.S. I'm very new to React so this might not be the best way to do this. If there is a better way please let me know.