Select current display value by default on EnumSwitch

This commit is contained in:
Fabio Manganiello 2023-01-03 23:14:57 +01:00
parent 01727f53bc
commit 13eb515f87
Signed by: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -18,7 +18,7 @@
:class="{'fa-angle-up': expanded, 'fa-angle-down': !expanded}" /> :class="{'fa-angle-up': expanded, 'fa-angle-down': !expanded}" />
</button> </button>
<span class="value" <span class="value"
v-text="value.value" v-text="value.values[value.value] || value.value"
v-if="value?.value != null" /> v-if="value?.value != null" />
</div> </div>
</div> </div>
@ -26,9 +26,15 @@
<div class="body" v-if="expanded" @click.stop="prevent"> <div class="body" v-if="expanded" @click.stop="prevent">
<div class="row"> <div class="row">
<div class="input"> <div class="input">
<select @input="setValue" ref="values"> <select @input="setValue" ref="values" :disabled="loading">
<option value="" v-if="value.is_write_only" selected>--</option> <option value="" v-if="value.is_write_only" selected>--</option>
<option :value="v" v-for="v in value.values" :key="v" v-text="v" /> <option
:value="value_id"
:selected="value_id == value.value"
:key="value_id"
v-for="text, value_id in value.values"
v-text="text"
/>
</select> </select>
</div> </div>
</div> </div>
@ -53,7 +59,7 @@ export default {
computed: { computed: {
hasValues() { hasValues() {
return !!this?.value?.values?.length return !!Object.values(this?.value?.values || {}).length
} }
}, },
@ -108,8 +114,13 @@ export default {
} }
.body { .body {
padding: 1em !important;
display: flex;
.row { .row {
width: 100%;
display: flex; display: flex;
text-align: center;
.icon { .icon {
width: 2em; width: 2em;
@ -117,7 +128,7 @@ export default {
} }
.input { .input {
width: calc(100% - 2em); width: 100%;
select { select {
width: 100%; width: 100%;