My form is set up with category labels and check boxes for each category as shown in the images below:
https://i.sstatic.net/nsfV7.png
I am using axios to fetch data from a Google sheet in this specific format:
https://i.sstatic.net/tgtWP.png
This is the script I have implemented to retrieve the values:
data() {
return {
form: {
email: "",
name: "",
phoneNo: "",
checked: []
},
sports: [],
arts: [],
dance: [],
show: true
};
},
methods: {
getCcaList() {
this.axios
.get(
"(Google sheet batch get API)"
)
.then(response => {
let cellValues = response.data.valueRanges[0].values;
// Manipulate the cellValues array to populate appropriate categories
for (let i = 0; i < cellValues[0].length; i++) {
if (cellValues[1][i] === "Sports")
this.sports.push(cellValues[0][i]);
else if (cellValues[1][i] === "Arts")
this.arts.push(cellValues[0][i]);
else if (cellValues[1][i] === "Dance")
this.dance.push(cellValues[0][i]);
}
});
}
The design of my HTML with vue-bootstrap looks like this:
<label for="sports">Sports:</label>
<br />
<b-form-checkbox-group v-model="form.checked" name="sports" :options="sports" stacked buttons></b-form-checkbox-group>
<br />
<label for="dance">Dance:</label>
<br />
<b-form-checkbox-group v-model="form.checked" name="dance" :options="dance" stacked buttons></b-form-checkbox-group>
<br />
<label for="arts">Arts:</label>
<br />
<b-form-checkbox-group v-model="form.checked" name="arts" :options="arts" stacked buttons></b-form-checkbox-group>
I'm exploring ways of creating the above structure without needing to adjust arrays when adding or removing categories in the spreadsheet.
One approach I've attempted involves using a dictionary to store values from the Google sheet and then utilizing v-for to display the category values. However, I'm encountering difficulties in displaying each value in the club array based on their respective categories.
[
{ category: "Sports", club: ["Basketball", "Soccer", "Archery"] },
{ category: "Dance", club: ["Salsa"] },
{ category: "Arts", club: ["Painting", "Choir", "Band", "Drawing"] },
]