Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
fix: selector value binding (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
hay-kot authored Oct 15, 2022
1 parent bb86a51 commit 5596740
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
20 changes: 13 additions & 7 deletions frontend/components/Form/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</template>

<script lang="ts" setup>
const emit = defineEmits(["update:modelValue"]);
const emit = defineEmits(["update:modelValue", "update:value"]);
const props = defineProps({
label: {
type: String,
Expand All @@ -37,26 +37,32 @@
type: String,
default: "name",
},
value: {
valueKey: {
type: String,
default: null,
required: false,
},
value: {
type: String,
default: "",
},
});
const selectedIdx = ref(-1);
const internalSelected = useVModel(props, "modelValue", emit);
watch(selectedIdx, newVal => {
internalSelected.value = props.items[newVal];
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function compare(a: any, b: any): boolean {
if (props.value) {
return a[props.value] === b[props.value];
watch(internalSelected, newVal => {
if (props.valueKey) {
emit("update:value", newVal[props.valueKey]);
}
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function compare(a: any, b: any): boolean {
if (a === b) {
return true;
}
Expand Down
14 changes: 12 additions & 2 deletions frontend/pages/item/[id]/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
loading: false,
// Values
obj: {},
id: "",
title: "",
type: "",
Expand All @@ -248,11 +249,13 @@
editState.title = attachment.document.title;
editState.type = attachment.type;
editState.modal = true;
editState.obj = attachmentOpts.find(o => o.value === attachment.type);
}
async function updateAttachment() {
editState.loading = true;
console.log(editState.type);
const { error, data } = await api.items.updateAttachment(itemId.value, editState.id, {
title: editState.title,
type: editState.type,
Expand Down Expand Up @@ -282,7 +285,14 @@
<template #title> Attachment Edit </template>

<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">
<BaseButton :loading="editState.loading" @click="updateAttachment"> Update </BaseButton>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
</template>

<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>

<div class="mt-4 flex justify-end">
Expand Down

0 comments on commit 5596740

Please sign in to comment.