I am currently working on a housing form and I have encountered a roadblock that I need assistance with. Essentially, when a user selects that their house has 2 floors in the form, they are then prompted to input the number of rooms, toilets, balconies, etc. for each floor.
The challenge I am facing is how to effectively "group" these responses so that I can send them to the backend and interpret the answers correctly.
Here is what I have attempted thus far:
data() {
return {
flooroptions: [
{
name: 'Rooms',
id: '1',
},
{
name: 'Balcony',
id: '2',
},
{
name: 'Toilets',
id: '3',
},
],
floors: '',
floor1: [],
},
}
By looping through like this:
<div class="" v-for="(opt, index) in flooroptions">
<input type="number" name="" value="" v-model="floor1[index]">
</div>
I am able to view my data using floor1:
{{ floor1 }}
However, if a user only inputs that the first floor has 2 rooms without adding any other information, I only receive 2 within floor1.
What would be the most effective approach to tackle this issue?
PS. Each floor will go through this flooroptions loop allowing users to input the number of each option for every floor, and my goal is to accurately interpret those numbers.