ldc-supportweb/resources/js/components/MarkerLabelSelectComponent.vue
Jérémy Munsch d52edeb6bc
MacroPlanning functionnality
bump kwaadpepper/crud-policies
2022-05-04 17:34:56 +02:00

52 lines
1.4 KiB
Vue

<template>
<div>
<v-select v-model="value" :options="labels" @search="addOption"/>
<input type="hidden" :value="inputValue" :name="name" />
</div>
</template>
<script>
export default {
mounted() {
this.labels = JSON.parse(this.dbLabels)
this.inputValue = this.dbValue
this.value = {
code: this.labels.length,
label: this.inputValue
}
for (let label of this.labels) {
label.default = true
if (label.label == this.dbValue) {
this.value = label
}
}
},
props: [
'name', 'dbValue', 'dbLabels'
],
data() {
return {
value: {},
inputValue: '',
labels: []
}
},
watch: {
value() {
this.inputValue = this.value.label
}
},
methods: {
addOption(newOption) {
if(newOption.length) {
for (let key in this.labels) {
if(!this.labels[key].default) {
this.labels.splice(key, 1)
}
}
this.labels.push({label: newOption, code: this.labels.length})
}
}
}
}
</script>