1
0
Fork 0
mirror of synced 2024-06-03 02:55:14 +12:00

Add internal setting to fully disable form validation

This commit is contained in:
Andrew Kingston 2022-04-04 08:49:01 +01:00
parent 2e979846c4
commit 91e35ef816
2 changed files with 24 additions and 14 deletions

View file

@ -9,6 +9,10 @@
export let disabled = false
export let actionType = "Create"
// Not exposed as a builder setting. Used internally to disable validation
// for fields rendered in things like search blocks.
export let disableValidation = false
const context = getContext("context")
const { API, fetchDatasourceSchema } = getContext("sdk")
@ -102,6 +106,7 @@
{schema}
{table}
{initialValues}
{disableValidation}
>
<slot />
</InnerForm>

View file

@ -10,6 +10,7 @@
export let size
export let schema
export let table
export let disableValidation = false
const component = getContext("component")
const { styleable, Provider, ActionTypes } = getContext("sdk")
@ -141,12 +142,14 @@
// Create validation function based on field schema
const schemaConstraints = schema?.[field]?.constraints
const validator = createValidatorFromConstraints(
schemaConstraints,
validationRules,
field,
table
)
const validator = disableValidation
? null
: createValidatorFromConstraints(
schemaConstraints,
validationRules,
field,
table
)
// If we've already registered this field then keep some existing state
let initialValue = Helpers.deepGet(initialValues, field) ?? defaultValue
@ -164,7 +167,7 @@
// 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)
initialError = validator?.(initialValue)
}
}
@ -254,7 +257,7 @@
}
// Update field state
const error = validator ? validator(value) : null
const error = validator?.(value)
fieldInfo.update(state => {
state.fieldState.value = value
state.fieldState.error = error
@ -288,12 +291,14 @@
// Create new validator
const schemaConstraints = schema?.[field]?.constraints
const validator = createValidatorFromConstraints(
schemaConstraints,
validationRules,
field,
table
)
const validator = disableValidation
? null
: createValidatorFromConstraints(
schemaConstraints,
validationRules,
field,
table
)
// Update validator
fieldInfo.update(state => {