Browse Source

Merge pull request #4033 from Budibase/fix/dynamic-validators

Fix dynamic validators not correctly validating form components
pull/4107/head
Andrew Kingston 5 years ago
committed by GitHub
parent
commit
e5f10e4fc3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      packages/client/src/components/app/forms/InnerForm.svelte

27
packages/client/src/components/app/forms/InnerForm.svelte

@ -141,8 +141,18 @@
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
let initialValue = deepGet(initialValues, field) ?? defaultValue
let initialError = null
let fieldId = `id-${generateID()}`
const existingField = getField(field)
if (existingField) {
@ -156,20 +166,17 @@
} else {
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
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
const fieldInfo = writable({
name: field,
@ -178,7 +185,7 @@
fieldState: {
fieldId,
value: initialValue,
error: null,
error: initialError,
disabled: disabled || fieldDisabled || isAutoColumn,
defaultValue,
validator,

Loading…
Cancel
Save