1
0
Fork 0
mirror of synced 2024-09-29 16:51:33 +13:00

Merge pull request #4083 from mslourens/save_non_required_multiselect

make empty array valid when not required
This commit is contained in:
Andrew Kingston 2022-01-18 15:24:12 +00:00 committed by GitHub
commit 6b23dcb004
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -61,12 +61,17 @@ exports.validate = async ({ appId, tableId, row, table }) => {
let res let res
// Validate.js doesn't seem to handle array // Validate.js doesn't seem to handle array
if (type === FieldTypes.ARRAY && row[fieldName] && row[fieldName].length) { if (type === FieldTypes.ARRAY && row[fieldName]) {
row[fieldName].map(val => { if (row[fieldName].length) {
if (!constraints.inclusion.includes(val)) { row[fieldName].map(val => {
errors[fieldName] = "Field not in list" if (!constraints.inclusion.includes(val)) {
} errors[fieldName] = "Field not in list"
}) }
})
} else if (constraints.presence && row[fieldName].length === 0) {
// 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.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 {