Merge pull request #8472 from Budibase/bug/sev3/validation-error-attachments
Validation error attachments
This commit is contained in:
commit
a9575db549
|
@ -43,6 +43,7 @@
|
||||||
let selectedImageIdx = 0
|
let selectedImageIdx = 0
|
||||||
let fileDragged = false
|
let fileDragged = false
|
||||||
let selectedUrl
|
let selectedUrl
|
||||||
|
let fileInput
|
||||||
$: selectedImage = value?.[selectedImageIdx] ?? null
|
$: selectedImage = value?.[selectedImageIdx] ?? null
|
||||||
$: fileCount = value?.length ?? 0
|
$: fileCount = value?.length ?? 0
|
||||||
$: isImage =
|
$: isImage =
|
||||||
|
@ -102,6 +103,7 @@
|
||||||
await deleteAttachments(
|
await deleteAttachments(
|
||||||
value.filter((x, idx) => idx === selectedImageIdx).map(item => item.key)
|
value.filter((x, idx) => idx === selectedImageIdx).map(item => item.key)
|
||||||
)
|
)
|
||||||
|
fileInput.value = ""
|
||||||
}
|
}
|
||||||
selectedImageIdx = 0
|
selectedImageIdx = 0
|
||||||
}
|
}
|
||||||
|
@ -234,6 +236,7 @@
|
||||||
type="file"
|
type="file"
|
||||||
multiple
|
multiple
|
||||||
accept={extensions}
|
accept={extensions}
|
||||||
|
bind:this={fileInput}
|
||||||
on:change={handleFile}
|
on:change={handleFile}
|
||||||
/>
|
/>
|
||||||
<svg
|
<svg
|
||||||
|
|
|
@ -82,10 +82,20 @@ exports.validate = async ({ tableId, row, table }) => {
|
||||||
// non required MultiSelect creates an empty array, which should not throw errors
|
// non required MultiSelect creates an empty array, which should not throw errors
|
||||||
errors[fieldName] = [`${fieldName} is required`]
|
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
|
// this should only happen if there is an error
|
||||||
try {
|
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) {
|
} catch (err) {
|
||||||
errors[fieldName] = [`Contains invalid JSON`]
|
errors[fieldName] = [`Contains invalid JSON`]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue