Answer the question
In order to leave comments, you need to log in
Dependency of several selects?
Hello, please tell me
there is such a custom select
<template>
<div>
<div class="vue-dropdown" :class="{'vue-active':toggle}">
<span @click="toggle = !toggle">{{ value.length ? value : defaultValue }}</span>
<div class="vue-dropdown-collapsed" v-if="this.toggle">
<input type="text" v-model="search" v-if="showSearch === 'true'" :placeholder="inputPlaceholder" @click="toggle == true">
<ul>
<li v-for="(option, index) in options" :key="index" @click="toggle = false, value = option.name, selectedItem = option" v-if="option.name.toLowerCase().indexOf(search.toLowerCase()) !== -1">{{ option.name }}</li>
</ul>
</div>
</div>
</div>
</template>
<script>
import axios from 'axios';
export default {
props: [
"options",
"defaultValue",
"showSearch",
"inputPlaceholder"
],
data() {
return {
toggle: false,
selectedItem: '',
value: "",
search: ""
};
},
watch: {
toggle: function (val) {
if(val) {
this.$emit('open');
} else {
this.search = '';
}
},
selectedItem: function(val) {
this.$emit('selectedItem', val)
}
},
methods: {}
}
</script>
formFields: [
{
name: 'brand',
type: 'select',
active: true,
fields: [
{
id: 0,
name: 'audi',
value: 'audi'
},
{
id: 1,
name: 'bmw',
value: 'bmw'
},
{
id: 2,
name: 'feat',
value: 'feat'
},
{
id: 3,
name: 'shkoda',
value: 'shkoda'
},
{
id: 4,
name: 'MB',
value: 'MB'
},
{
id: 5,
name: 'seat',
value: 'seat'
},
{
id: 6,
name: 'mazda',
value: 'mazda'
},
]
},
{
name: 'model',
type: 'select',
depend: ["brand"],
active: false,
fields: []
},
{
name: 'country',
type: 'select',
depend: ["brand"],
active: false,
fields: []
},
{
name: 'country',
type: 'input',
depend: ["brand"],
active: false,
fields: []
}
]
<div v-for="(field, index) in formFields" :key="index">
<ui_input v-if="field.type == 'input'" v-model="input" @change="change($event)"></ui_input>
<dropdown :id="field.id" @selectedItem="selected($event)" v-else-if="field.type == 'select'" :options="field.fields" default-value="Make a choice" show-search="true" input-placeholder="Выберите"></dropdown>
</div>
methods: {
selected(val) {
axios.get('../../../static/json/v1/models/' + val.id + '.json').then(response => {
console.log(response.data)
}).catch(e => {
console.log(e)
})
}
},
Answer the question
In order to leave comments, you need to log in
how to make dependency? That is, select model should not be active until select brand is selected.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question