Map attachment string to array if needed

This commit is contained in:
Mel O'Hagan 2022-11-01 15:59:04 +00:00
parent 5dc6f6dfa0
commit 194da4bee1
1 changed files with 12 additions and 2 deletions

View File

@ -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`]
} }