From 702e7fe184cc244c1ca8ec8d9f7fc96c1a59220b Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Tue, 1 Nov 2022 15:59:04 +0000 Subject: [PATCH 1/2] Map attachment string to array if needed --- packages/server/src/api/controllers/row/utils.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/row/utils.js b/packages/server/src/api/controllers/row/utils.js index 4c837e7630..ca2ad02a30 100644 --- a/packages/server/src/api/controllers/row/utils.js +++ b/packages/server/src/api/controllers/row/utils.js @@ -82,10 +82,20 @@ exports.validate = async ({ tableId, row, table }) => { // non required MultiSelect creates an empty array, which should not throw errors errors[fieldName] = [`${fieldName} is required`] } - } else if (type === FieldTypes.JSON && typeof row[fieldName] === "string") { + } else if ( + (type === FieldTypes.ATTACHMENT || type === FieldTypes.JSON) && + typeof row[fieldName] === "string" + ) { // this should only happen if there is an error try { - JSON.parse(row[fieldName]) + const json = JSON.parse(row[fieldName]) + if (type === FieldTypes.ATTACHMENT) { + if (Array.isArray(json)) { + row[fieldName] = json + } else { + errors[fieldName] = [`Must be an array`] + } + } } catch (err) { errors[fieldName] = [`Contains invalid JSON`] } From ebeae5742ac1f9a5fd0b5388241f5dff73f193e6 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Tue, 1 Nov 2022 16:43:18 +0000 Subject: [PATCH 2/2] Clear file input when removing files --- packages/bbui/src/Form/Core/Dropzone.svelte | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/bbui/src/Form/Core/Dropzone.svelte b/packages/bbui/src/Form/Core/Dropzone.svelte index 51f6eef6f9..c64e69b201 100644 --- a/packages/bbui/src/Form/Core/Dropzone.svelte +++ b/packages/bbui/src/Form/Core/Dropzone.svelte @@ -43,6 +43,7 @@ let selectedImageIdx = 0 let fileDragged = false let selectedUrl + let fileInput $: selectedImage = value?.[selectedImageIdx] ?? null $: fileCount = value?.length ?? 0 $: isImage = @@ -102,6 +103,7 @@ await deleteAttachments( value.filter((x, idx) => idx === selectedImageIdx).map(item => item.key) ) + fileInput.value = "" } selectedImageIdx = 0 } @@ -234,6 +236,7 @@ type="file" multiple accept={extensions} + bind:this={fileInput} on:change={handleFile} />