Fix for missing attachment validation
This commit is contained in:
parent
f3e9030c3a
commit
20c4bee20a
|
@ -86,6 +86,7 @@ const componentMap = {
|
||||||
"validation/boolean": ValidationEditor,
|
"validation/boolean": ValidationEditor,
|
||||||
"validation/datetime": ValidationEditor,
|
"validation/datetime": ValidationEditor,
|
||||||
"validation/attachment": ValidationEditor,
|
"validation/attachment": ValidationEditor,
|
||||||
|
"validation/attachment_single": ValidationEditor,
|
||||||
"validation/signature": ValidationEditor,
|
"validation/signature": ValidationEditor,
|
||||||
"validation/link": ValidationEditor,
|
"validation/link": ValidationEditor,
|
||||||
"validation/bb_reference": ValidationEditor,
|
"validation/bb_reference": ValidationEditor,
|
||||||
|
|
|
@ -108,6 +108,7 @@
|
||||||
Constraints.MaxFileSize,
|
Constraints.MaxFileSize,
|
||||||
Constraints.MaxUploadSize,
|
Constraints.MaxUploadSize,
|
||||||
],
|
],
|
||||||
|
["attachment_single"]: [Constraints.Required, Constraints.MaxUploadSize],
|
||||||
["signature"]: [Constraints.Required],
|
["signature"]: [Constraints.Required],
|
||||||
["link"]: [
|
["link"]: [
|
||||||
Constraints.Required,
|
Constraints.Required,
|
||||||
|
|
|
@ -4427,7 +4427,7 @@
|
||||||
"defaultValue": false
|
"defaultValue": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "validation/attachment",
|
"type": "validation/attachment_single",
|
||||||
"label": "Validation",
|
"label": "Validation",
|
||||||
"key": "validation"
|
"key": "validation"
|
||||||
},
|
},
|
||||||
|
|
|
@ -199,6 +199,14 @@ const parseType = (value, type) => {
|
||||||
return value
|
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
|
// Parse links, treating no elements as null
|
||||||
if (type === FieldTypes.LINK) {
|
if (type === FieldTypes.LINK) {
|
||||||
if (!Array.isArray(value) || !value.length) {
|
if (!Array.isArray(value) || !value.length) {
|
||||||
|
@ -245,10 +253,8 @@ const maxLengthHandler = (value, rule) => {
|
||||||
// Evaluates a max file size (MB) constraint
|
// Evaluates a max file size (MB) constraint
|
||||||
const maxFileSizeHandler = (value, rule) => {
|
const maxFileSizeHandler = (value, rule) => {
|
||||||
const limit = parseType(rule.value, "number")
|
const limit = parseType(rule.value, "number")
|
||||||
return (
|
const check = attachment => attachment.size / 1000000 > limit
|
||||||
value == null ||
|
return value == null || !(value?.key ? check(value) : value.some(check))
|
||||||
!value.some(attachment => attachment.size / 1000000 > limit)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluates a max total upload size (MB) constraint
|
// Evaluates a max total upload size (MB) constraint
|
||||||
|
@ -256,8 +262,11 @@ const maxUploadSizeHandler = (value, rule) => {
|
||||||
const limit = parseType(rule.value, "number")
|
const limit = parseType(rule.value, "number")
|
||||||
return (
|
return (
|
||||||
value == null ||
|
value == null ||
|
||||||
value.reduce((acc, currentItem) => acc + currentItem.size, 0) / 1000000 <=
|
(value?.key
|
||||||
limit
|
? value.size / 1000000 <= limit
|
||||||
|
: value.reduce((acc, currentItem) => acc + currentItem.size, 0) /
|
||||||
|
1000000 <=
|
||||||
|
limit)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue