Fixed BelongsToDropdown component: crashed when there was no value

This commit is contained in:
Noah Lancien 2023-10-02 14:28:16 +02:00
parent 36703bc9ac
commit 6b85d63f5e

View file

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