Merge pull request #4033 from Budibase/fix/dynamic-validators
Fix dynamic validators not correctly validating form components
This commit is contained in:
commit
603d38ad78
|
@ -141,8 +141,18 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create validation function based on field schema
|
||||||
|
const schemaConstraints = schema?.[field]?.constraints
|
||||||
|
const validator = createValidatorFromConstraints(
|
||||||
|
schemaConstraints,
|
||||||
|
validationRules,
|
||||||
|
field,
|
||||||
|
table
|
||||||
|
)
|
||||||
|
|
||||||
// If we've already registered this field then keep some existing state
|
// If we've already registered this field then keep some existing state
|
||||||
let initialValue = deepGet(initialValues, field) ?? defaultValue
|
let initialValue = deepGet(initialValues, field) ?? defaultValue
|
||||||
|
let initialError = null
|
||||||
let fieldId = `id-${generateID()}`
|
let fieldId = `id-${generateID()}`
|
||||||
const existingField = getField(field)
|
const existingField = getField(field)
|
||||||
if (existingField) {
|
if (existingField) {
|
||||||
|
@ -156,20 +166,17 @@
|
||||||
} else {
|
} else {
|
||||||
initialValue = fieldState.value ?? initialValue
|
initialValue = fieldState.value ?? initialValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If this field has already been registered and we previously had an
|
||||||
|
// error set, then re-run the validator to see if we can unset it
|
||||||
|
if (fieldState.error) {
|
||||||
|
initialError = validator(initialValue)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto columns are always disabled
|
// Auto columns are always disabled
|
||||||
const isAutoColumn = !!schema?.[field]?.autocolumn
|
const isAutoColumn = !!schema?.[field]?.autocolumn
|
||||||
|
|
||||||
// Create validation function based on field schema
|
|
||||||
const schemaConstraints = schema?.[field]?.constraints
|
|
||||||
const validator = createValidatorFromConstraints(
|
|
||||||
schemaConstraints,
|
|
||||||
validationRules,
|
|
||||||
field,
|
|
||||||
table
|
|
||||||
)
|
|
||||||
|
|
||||||
// Construct field info
|
// Construct field info
|
||||||
const fieldInfo = writable({
|
const fieldInfo = writable({
|
||||||
name: field,
|
name: field,
|
||||||
|
@ -178,7 +185,7 @@
|
||||||
fieldState: {
|
fieldState: {
|
||||||
fieldId,
|
fieldId,
|
||||||
value: initialValue,
|
value: initialValue,
|
||||||
error: null,
|
error: initialError,
|
||||||
disabled: disabled || fieldDisabled || isAutoColumn,
|
disabled: disabled || fieldDisabled || isAutoColumn,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
validator,
|
validator,
|
||||||
|
|
Loading…
Reference in New Issue