From 6b85d63f5edf4ad7cf7fa9b993c359b1d16ba9da Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Mon, 2 Oct 2023 14:28:16 +0200 Subject: [PATCH] Fixed BelongsToDropdown component: crashed when there was no value --- resources/ts/components/BelongsToDropdown.vue | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/resources/ts/components/BelongsToDropdown.vue b/resources/ts/components/BelongsToDropdown.vue index 8accf2a..4d2c912 100644 --- a/resources/ts/components/BelongsToDropdown.vue +++ b/resources/ts/components/BelongsToDropdown.vue @@ -109,18 +109,20 @@ export default defineComponent({ methods: { parseTags(intSelectedItem: number[]): CustomTag[] { const out: CustomTag[] = []; - intSelectedItem.forEach((intItem: number) => { - const selectedItem = this.allItems.find(item => String(item.id) === String(intItem)); - if (!selectedItem) { - console.debug(intItem); - throw new Error(`Could not find enum ${intItem}`); - } - out.push({ - id: String(selectedItem.id), - value: String(selectedItem.id), - text: String(selectedItem[`${this.labelField}`]) - } as LaravelModel as CustomTag); - }); + if (intSelectedItem[0] !== null) { + intSelectedItem.forEach((intItem: number) => { + const selectedItem = this.allItems.find(item => String(item.id) === String(intItem)); + if (!selectedItem) { + console.debug(intItem); + throw new Error(`Could not find enum ${intItem}`); + } + out.push({ + id: String(selectedItem.id), + value: String(selectedItem.id), + text: String(selectedItem[`${this.labelField}`]) + } as LaravelModel as CustomTag); + }); + } return out; }, parseNewlyCreated(newModel: LaravelModel): CustomTag {