forked from mirrors/homebox
fix: selector value binding (#87)
This commit is contained in:
parent
bb86a51b05
commit
5596740cd2
3 changed files with 26 additions and 10 deletions
|
@ -17,7 +17,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
const emit = defineEmits(["update:modelValue"]);
|
const emit = defineEmits(["update:modelValue", "update:value"]);
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
label: {
|
label: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -37,26 +37,32 @@
|
||||||
type: String,
|
type: String,
|
||||||
default: "name",
|
default: "name",
|
||||||
},
|
},
|
||||||
value: {
|
valueKey: {
|
||||||
type: String,
|
type: String,
|
||||||
default: null,
|
default: null,
|
||||||
required: false,
|
},
|
||||||
|
value: {
|
||||||
|
type: String,
|
||||||
|
default: "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const selectedIdx = ref(-1);
|
const selectedIdx = ref(-1);
|
||||||
|
|
||||||
const internalSelected = useVModel(props, "modelValue", emit);
|
const internalSelected = useVModel(props, "modelValue", emit);
|
||||||
|
|
||||||
watch(selectedIdx, newVal => {
|
watch(selectedIdx, newVal => {
|
||||||
internalSelected.value = props.items[newVal];
|
internalSelected.value = props.items[newVal];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(internalSelected, newVal => {
|
||||||
|
if (props.valueKey) {
|
||||||
|
emit("update:value", newVal[props.valueKey]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
function compare(a: any, b: any): boolean {
|
function compare(a: any, b: any): boolean {
|
||||||
if (props.value) {
|
|
||||||
return a[props.value] === b[props.value];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a === b) {
|
if (a === b) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,6 +233,7 @@
|
||||||
loading: false,
|
loading: false,
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
|
obj: {},
|
||||||
id: "",
|
id: "",
|
||||||
title: "",
|
title: "",
|
||||||
type: "",
|
type: "",
|
||||||
|
@ -248,11 +249,13 @@
|
||||||
editState.title = attachment.document.title;
|
editState.title = attachment.document.title;
|
||||||
editState.type = attachment.type;
|
editState.type = attachment.type;
|
||||||
editState.modal = true;
|
editState.modal = true;
|
||||||
|
|
||||||
|
editState.obj = attachmentOpts.find(o => o.value === attachment.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateAttachment() {
|
async function updateAttachment() {
|
||||||
editState.loading = true;
|
editState.loading = true;
|
||||||
|
console.log(editState.type);
|
||||||
const { error, data } = await api.items.updateAttachment(itemId.value, editState.id, {
|
const { error, data } = await api.items.updateAttachment(itemId.value, editState.id, {
|
||||||
title: editState.title,
|
title: editState.title,
|
||||||
type: editState.type,
|
type: editState.type,
|
||||||
|
@ -282,7 +285,14 @@
|
||||||
<template #title> Attachment Edit </template>
|
<template #title> Attachment Edit </template>
|
||||||
|
|
||||||
<FormTextField v-model="editState.title" label="Attachment Title" />
|
<FormTextField v-model="editState.title" label="Attachment Title" />
|
||||||
<FormSelect v-model="editState.type" label="Attachment Type" value="value" name="text" :items="attachmentOpts" />
|
<FormSelect
|
||||||
|
v-model="editState.obj"
|
||||||
|
v-model:value="editState.type"
|
||||||
|
label="Attachment Type"
|
||||||
|
value-key="value"
|
||||||
|
name="text"
|
||||||
|
:items="attachmentOpts"
|
||||||
|
/>
|
||||||
<div class="modal-action">
|
<div class="modal-action">
|
||||||
<BaseButton :loading="editState.loading" @click="updateAttachment"> Update </BaseButton>
|
<BaseButton :loading="editState.loading" @click="updateAttachment"> Update </BaseButton>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -226,7 +226,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div v-if="group" class="p-5 pt-0">
|
<div v-if="group" class="p-5 pt-0">
|
||||||
<FormSelect v-model="currency" value="code" label="Currency Format" :items="currencies" />
|
<FormSelect v-model="currency" label="Currency Format" :items="currencies" />
|
||||||
<p class="m-2 text-sm">Example: {{ currencyExample }}</p>
|
<p class="m-2 text-sm">Example: {{ currencyExample }}</p>
|
||||||
|
|
||||||
<div class="mt-4 flex justify-end">
|
<div class="mt-4 flex justify-end">
|
||||||
|
|
Loading…
Reference in a new issue