From 468ee7ac0c60020c1c343dd9897c946e26d6dcce Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 25 Feb 2021 11:09:00 +0000 Subject: [PATCH] Fixing an issue with option fields not being unselectable. --- packages/server/src/api/controllers/row.js | 14 ++++++++++---- packages/server/src/utilities/rowProcessor.js | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/server/src/api/controllers/row.js b/packages/server/src/api/controllers/row.js index 4ce664413e..413fedc6cd 100644 --- a/packages/server/src/api/controllers/row.js +++ b/packages/server/src/api/controllers/row.js @@ -15,6 +15,7 @@ const { } = require("../../utilities/rowProcessor") const { FieldTypes } = require("../../constants") const { isEqual } = require("lodash") +const { cloneDeep } = require("lodash/fp") const TABLE_VIEW_BEGINS_WITH = `all${SEPARATOR}${DocumentTypes.TABLE}${SEPARATOR}` @@ -351,10 +352,15 @@ async function validate({ appId, tableId, row, table }) { } const errors = {} for (let fieldName of Object.keys(table.schema)) { - const res = validateJs.single( - row[fieldName], - table.schema[fieldName].constraints - ) + const constraints = cloneDeep(table.schema[fieldName].constraints) + // special case for options, need to always allow unselected (null) + if ( + table.schema[fieldName].type === FieldTypes.OPTIONS && + constraints.inclusion + ) { + constraints.inclusion.push(null) + } + const res = validateJs.single(row[fieldName], constraints) if (res) errors[fieldName] = res } return { valid: Object.keys(errors).length === 0, errors } diff --git a/packages/server/src/utilities/rowProcessor.js b/packages/server/src/utilities/rowProcessor.js index eea34efc30..ee2a05f856 100644 --- a/packages/server/src/utilities/rowProcessor.js +++ b/packages/server/src/utilities/rowProcessor.js @@ -25,7 +25,7 @@ const TYPE_TRANSFORM_MAP = { }, }, [FieldTypes.OPTIONS]: { - "": "", + "": null, [null]: "", [undefined]: undefined, },