Combine table schema validation rules with custom validation rules when validating form fields

This commit is contained in:
Andrew Kingston 2021-08-10 14:36:47 +01:00
parent d79748bfd9
commit b4f51d44d5
1 changed files with 13 additions and 3 deletions

View File

@ -21,7 +21,12 @@
// Form API contains functions to control the form // Form API contains functions to control the form
const formApi = { const formApi = {
registerField: (field, defaultValue = null, fieldDisabled = false) => { registerField: (
field,
defaultValue = null,
fieldDisabled = false,
validationRules
) => {
if (!field) { if (!field) {
return return
} }
@ -30,8 +35,13 @@
const isAutoColumn = !!schema?.[field]?.autocolumn const isAutoColumn = !!schema?.[field]?.autocolumn
// Create validation function based on field schema // Create validation function based on field schema
const constraints = schema?.[field]?.constraints const schemaConstraints = schema?.[field]?.constraints
const validate = createValidatorFromConstraints(constraints, field, table) const validate = createValidatorFromConstraints(
schemaConstraints,
validationRules,
field,
table
)
// Construct field object // Construct field object
fieldMap[field] = { fieldMap[field] = {