DigitalConsumer.ISS/src/layouts/vehicle-selection/vehicle-question/vehicle-question.vue

58 lines
1.4 KiB
Vue

<template>
<dropdownQuestion
v-model="selectedValue"
:options="values"
disableAutoFill
placeHolderText="Select an option"
:isDisabled="!values.length" />
</template>
<script>
import dropdownQuestion from '@/digital-components/dropdown-question/dropdown-question.vue';
export default {
name: 'vehicle-question',
components: {
dropdownQuestion
},
props: {
modelValue: String,
updateValues: Function
},
emits: ['update:modelValue'],
data() {
return {
values: [],
selectedIndex: null
};
},
computed: {
selectedValue: {
get() {
return this.selectedIndex?.toString();
},
set(newValue) {
this.selectedIndex = newValue;
newValue = newValue != null && newValue > -1 ? this.values[newValue] : null;
this.$emit('update:modelValue', newValue);
}
}
},
methods: {
async getNewValues() {
const results = await this.updateValues();
this.values = results?.data;
if (this.values.length === 1) {
this.selectedValue = 0;
} else {
this.selectedValue = null;
}
},
clearValues() {
this.values = [];
this.selectedValue = null;
}
}
};
</script>