diff --git a/frontend/components/Form/Multiselect.vue b/frontend/components/Form/Multiselect.vue index e961f7f36..b9b58ad38 100644 --- a/frontend/components/Form/Multiselect.vue +++ b/frontend/components/Form/Multiselect.vue @@ -9,23 +9,28 @@ {{ name != "" ? itm[name] : itm }} - +
+ +
+ + @@ -49,6 +54,10 @@ type: String, default: "name", }, + uniqueField: { + type: String, + default: "id", + }, selectFirst: { type: Boolean, default: false, @@ -57,19 +66,26 @@ const value = useVModel(props, "modelValue", emit); - const selected = computed>(() => { - const obj: Record = {}; - value.value.forEach(itm => { - const idx = props.items.findIndex(item => item[props.name] === itm.name); - obj[idx] = true; + const search = ref(""); + + const filteredItems = computed(() => { + if (!search.value) { + return props.items; + } + + return props.items.filter(item => { + return item[props.name].toLowerCase().includes(search.value.toLowerCase()); }); - return obj; }); - function toggle(index: number) { - const item = props.items[index]; - if (selected.value[index]) { - value.value = value.value.filter(itm => itm.name !== item.name); + const selected = computed(() => { + return value.value.map(itm => itm[props.uniqueField]); + }); + + function toggle(uniqueField: string) { + const item = props.items.find(itm => itm[props.uniqueField] === uniqueField); + if (selected.value.includes(item[props.uniqueField])) { + value.value = value.value.filter(itm => itm[props.uniqueField] !== item[props.uniqueField]); } else { value.value = [...value.value, item]; }