2021-12-29 13:08:48 +01:00
|
|
|
<template>
|
2022-01-03 15:28:12 +01:00
|
|
|
<div class="ui-native-select" :disabled="config.disabled">
|
|
|
|
|
<select :value="value" @input="onChange" :disabled="config.disabled">
|
2021-12-29 13:08:48 +01:00
|
|
|
<option v-if="emptyOption"></option>
|
|
|
|
|
<option v-for="option in options" :value="option.value" v-localize="option.label"></option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
props: {
|
|
|
|
|
value: [String, Number],
|
|
|
|
|
config: Object,
|
|
|
|
|
items: [Array, Function],
|
|
|
|
|
emptyOption: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
data: () => ({
|
|
|
|
|
options: []
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
created()
|
|
|
|
|
{
|
|
|
|
|
this.rebuild();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
|
items: {
|
|
|
|
|
deep: true,
|
2022-01-14 11:51:38 +01:00
|
|
|
handler(val)
|
2021-12-29 13:08:48 +01:00
|
|
|
{
|
2022-01-14 11:51:38 +01:00
|
|
|
if (typeof val !== 'function')
|
|
|
|
|
{
|
|
|
|
|
this.rebuild();
|
|
|
|
|
}
|
2021-12-29 13:08:48 +01:00
|
|
|
}
|
|
|
|
|
},
|
2022-01-14 11:51:38 +01:00
|
|
|
'config.model': {
|
2021-12-29 13:08:48 +01:00
|
|
|
deep: true,
|
|
|
|
|
handler()
|
|
|
|
|
{
|
|
|
|
|
this.rebuild();
|
|
|
|
|
this.onChange({ target: { value: this.value } });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
rebuild()
|
|
|
|
|
{
|
|
|
|
|
let items = [];
|
2022-01-14 11:51:38 +01:00
|
|
|
let options = [];
|
2021-12-29 13:08:48 +01:00
|
|
|
|
|
|
|
|
if (!this.config.model || !this.items)
|
|
|
|
|
{
|
2022-01-14 11:51:38 +01:00
|
|
|
options = items;
|
2021-12-29 13:08:48 +01:00
|
|
|
}
|
2022-01-14 11:51:38 +01:00
|
|
|
else if (typeof this.items === 'function')
|
2021-12-29 13:08:48 +01:00
|
|
|
{
|
2022-01-14 11:51:38 +01:00
|
|
|
options = this.items(this.config.model);
|
2021-12-29 13:08:48 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-01-14 11:51:38 +01:00
|
|
|
options = [...this.items];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (JSON.stringify(options) !== JSON.stringify(this.options))
|
|
|
|
|
{
|
|
|
|
|
this.options = options;
|
2021-12-29 13:08:48 +01:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onChange(ev)
|
|
|
|
|
{
|
2022-01-03 15:28:12 +01:00
|
|
|
let value = ev.target.value || null;
|
|
|
|
|
|
|
|
|
|
if (value && !this.options.find(x => x.value == value))
|
|
|
|
|
{
|
|
|
|
|
value = null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-14 11:51:38 +01:00
|
|
|
if (this.value === value)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 15:28:12 +01:00
|
|
|
this.$emit('input', value);
|
2022-01-14 11:51:38 +01:00
|
|
|
this.$emit('update:value', value);
|
2021-12-29 13:08:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|