I am working on a react project where I have a text input which will take input values n number of times.The screen looks like this:
After clicking Next , the value will get submitted in the next page, and we can come back to enter more values in the text box in the page shown in the screenshot below. For each value that I have entered in the , there will be a corresponding radio button value. So, I have created an array in the state which will have the values of the textbox .
this.state = {
buildingNames: [],
selectedOptions: ''
}
The selectedOptions state takes the radio button value. So, currently whenever a new value is added in the texbox I am pushing it to the buildingNames state.But I am not able to get how to get the corresponding radioButton value for each buildingName and push it as an array of objects. Currently, I am pushing the value of the text box into the array like:
const tempState = [...this.state.buildingNames];
tempState.push(inputData.value);
this.setState({buildingNames: tempState });
where inputData.value is the value entered in the text box.
So my final array should be like :
buildingDetails:[
{
buildingName:'abc'
radioButtonValue:'1'
},
{
buildingName:'def'
radioButtonValue:'2'
},
{
buildingName:'ghi'
radioButtonValue:'3'
},
// so on
]
I am not able to understand how to get the value of the radio button for the corresponding building. So, how do I proceed.Can anyone please guide me?
