I would like to show/hide certain options in select menu 2 depending on what is chosen in select 1 and also show/hide certain options in select menu 3 depending on what is chosen in select menu 2.
For example, if the user selects 'Subject01' in the first menu I would like to hide 'Subject04' and 'Subject08' in menu 2. If the user selects 'Subject016' in select 2, I would like to hide 'Subject11' in menu 3. I have several scenarios based on the subject selections. So these are just examples.
I can add a class to the but I don't know how to add to the individual tags.
Any help appreciated.
The code:
<template>
<select v-model="one" id="selectone">
<option v-for="subject in subjects" :key="subject">
{{ subject }}
</option>
</select>
<select v-model="two" :disabled="!one" id="selecttwo">
<option
v-for="subject in subjects.filter((item) =>
item.split(' ')[0].indexOf(this.one.split(' ')[0])
)"
:key="subject"
>
{{ subject }}
</option>
</select>
<select v-model="three" :disabled="!two" id="selectthree">
<option
v-for="subject in subjects.filter(
(item) =>
item.split(' ')[0].indexOf(this.one.split(' ')[0]) &&
item.split(' ')[0].indexOf(this.two.split(' ')[0])
)"
:key="subject"
>
{{ subject }}
</option>
</select>
<div v-if="one">You have selected: {{ one }} {{ two }} {{ three }}</div>
</template>
<script>
export default {
data() {
return {
subjects: [
"Subject01",
"Subject02",
"Subject03",
"Subject04",
"Subject05",
"Subject06",
"Subject07",
"Subject08",
"Subject09",
"Subject10",
"Subject11",
"Subject12",
"Subject13",
"Subject14",
"Subject15",
"Subject16",
],
one: "",
two: "",
three: "",
};
},
methods: {},
};
</script>
<style>
li {
list-style-type: none;
}
.hide {
display: none;
}
.show {
display: block;
}
</style>