From e0e99ba6f5c430904e0148a857706e0cc6f13144 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Mon, 23 Mar 2026 08:26:21 +0100 Subject: [PATCH] Fix #146 --- frontend/components/EntityEdit.vue | 44 +++++++++++++++++++++ frontend/components/StandardEntityModal.vue | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/frontend/components/EntityEdit.vue b/frontend/components/EntityEdit.vue index c0e6026..9e8d8f7 100644 --- a/frontend/components/EntityEdit.vue +++ b/frontend/components/EntityEdit.vue @@ -174,6 +174,49 @@ const setupQuery = () => { setupQuery() const loadedOptions = ref({}) + +const normalizeSelectFieldValue = (value, isMultiple = false) => { + if (isMultiple) { + if (!Array.isArray(value)) return [] + + return value.map((entry) => { + if (entry && typeof entry === "object" && "id" in entry) { + return entry.id + } + + return entry + }) + } + + if (value && typeof value === "object" && "id" in value) { + return value.id + } + + return value +} + +const normalizeLoadedSelectValues = () => { + dataType.templateColumns.forEach((datapoint) => { + if (datapoint.inputType !== "select") return + + if (datapoint.key.includes(".")) { + const [parentKey, childKey] = datapoint.key.split(".") + if (!item.value[parentKey]) return + + item.value[parentKey][childKey] = normalizeSelectFieldValue( + item.value[parentKey][childKey], + datapoint.selectMultiple + ) + return + } + + item.value[datapoint.key] = normalizeSelectFieldValue( + item.value[datapoint.key], + datapoint.selectMultiple + ) + }) +} + const loadOptions = async () => { let optionsToLoad = dataType.templateColumns.filter(i => i.selectDataType).map(i => { return { @@ -198,6 +241,7 @@ const loadOptions = async () => { } loadOptions() +normalizeLoadedSelectValues() const contentChanged = (content, datapoint) => { if (datapoint.key.includes(".")) { diff --git a/frontend/components/StandardEntityModal.vue b/frontend/components/StandardEntityModal.vue index 7e263c9..e076f04 100644 --- a/frontend/components/StandardEntityModal.vue +++ b/frontend/components/StandardEntityModal.vue @@ -75,7 +75,7 @@ setupPage() :type="props.type" :item="item" :inModal="true" - @return-data="(data) => emit('return-data',data)" + @return-data="(data) => emit('returnData', data)" :createQuery="props.createQuery" :mode="props.mode" />