1
0
Fork 0
mirror of synced 2024-10-05 20:44:47 +13:00

Fix for missing attachment validation

This commit is contained in:
Dean 2024-04-11 17:37:12 +01:00
parent f3e9030c3a
commit 20c4bee20a
4 changed files with 18 additions and 7 deletions

View file

@ -86,6 +86,7 @@ const componentMap = {
"validation/boolean": ValidationEditor,
"validation/datetime": ValidationEditor,
"validation/attachment": ValidationEditor,
"validation/attachment_single": ValidationEditor,
"validation/signature": ValidationEditor,
"validation/link": ValidationEditor,
"validation/bb_reference": ValidationEditor,

View file

@ -108,6 +108,7 @@
Constraints.MaxFileSize,
Constraints.MaxUploadSize,
],
["attachment_single"]: [Constraints.Required, Constraints.MaxUploadSize],
["signature"]: [Constraints.Required],
["link"]: [
Constraints.Required,

View file

@ -4427,7 +4427,7 @@
"defaultValue": false
},
{
"type": "validation/attachment",
"type": "validation/attachment_single",
"label": "Validation",
"key": "validation"
},

View file

@ -199,6 +199,14 @@ const parseType = (value, type) => {
return value
}
// Parse attachment single, treating no key as null
if (type === FieldTypes.ATTACHMENT_SINGLE) {
if (!value?.key) {
return null
}
return value
}
// Parse links, treating no elements as null
if (type === FieldTypes.LINK) {
if (!Array.isArray(value) || !value.length) {
@ -245,10 +253,8 @@ const maxLengthHandler = (value, rule) => {
// Evaluates a max file size (MB) constraint
const maxFileSizeHandler = (value, rule) => {
const limit = parseType(rule.value, "number")
return (
value == null ||
!value.some(attachment => attachment.size / 1000000 > limit)
)
const check = attachment => attachment.size / 1000000 > limit
return value == null || !(value?.key ? check(value) : value.some(check))
}
// Evaluates a max total upload size (MB) constraint
@ -256,8 +262,11 @@ const maxUploadSizeHandler = (value, rule) => {
const limit = parseType(rule.value, "number")
return (
value == null ||
value.reduce((acc, currentItem) => acc + currentItem.size, 0) / 1000000 <=
limit
(value?.key
? value.size / 1000000 <= limit
: value.reduce((acc, currentItem) => acc + currentItem.size, 0) /
1000000 <=
limit)
)
}