Merge pull request #2707 from mslourens/fix_constraint_formula_field

Fix formula constraints check
This commit is contained in:
Martin McKeaveney 2021-09-23 09:35:43 +01:00 committed by GitHub
commit 7768bbf9e1
1 changed files with 6 additions and 0 deletions

View File

@ -5,6 +5,7 @@ const { InternalTables } = require("../../../db/utils")
const userController = require("../user") const userController = require("../user")
const { FieldTypes } = require("../../../constants") const { FieldTypes } = require("../../../constants")
const { integrations } = require("../../../integrations") const { integrations } = require("../../../integrations")
const { processStringSync } = require("@budibase/string-templates")
validateJs.extend(validateJs.validators.datetime, { validateJs.extend(validateJs.validators.datetime, {
parse: function (value) { parse: function (value) {
@ -73,6 +74,11 @@ exports.validate = async ({ appId, tableId, row, table }) => {
errors[fieldName] = "Field not in list" errors[fieldName] = "Field not in list"
} }
}) })
} else if (table.schema[fieldName].type === FieldTypes.FORMULA) {
res = validateJs.single(
processStringSync(table.schema[fieldName].formula, row),
constraints
)
} else { } else {
res = validateJs.single(row[fieldName], constraints) res = validateJs.single(row[fieldName], constraints)
} }