Add internal setting to fully disable form validation
This commit is contained in:
parent
2e979846c4
commit
91e35ef816
|
@ -9,6 +9,10 @@
|
||||||
export let disabled = false
|
export let disabled = false
|
||||||
export let actionType = "Create"
|
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 context = getContext("context")
|
||||||
const { API, fetchDatasourceSchema } = getContext("sdk")
|
const { API, fetchDatasourceSchema } = getContext("sdk")
|
||||||
|
|
||||||
|
@ -102,6 +106,7 @@
|
||||||
{schema}
|
{schema}
|
||||||
{table}
|
{table}
|
||||||
{initialValues}
|
{initialValues}
|
||||||
|
{disableValidation}
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</InnerForm>
|
</InnerForm>
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
export let size
|
export let size
|
||||||
export let schema
|
export let schema
|
||||||
export let table
|
export let table
|
||||||
|
export let disableValidation = false
|
||||||
|
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
const { styleable, Provider, ActionTypes } = getContext("sdk")
|
const { styleable, Provider, ActionTypes } = getContext("sdk")
|
||||||
|
@ -141,12 +142,14 @@
|
||||||
|
|
||||||
// Create validation function based on field schema
|
// Create validation function based on field schema
|
||||||
const schemaConstraints = schema?.[field]?.constraints
|
const schemaConstraints = schema?.[field]?.constraints
|
||||||
const validator = createValidatorFromConstraints(
|
const validator = disableValidation
|
||||||
schemaConstraints,
|
? null
|
||||||
validationRules,
|
: createValidatorFromConstraints(
|
||||||
field,
|
schemaConstraints,
|
||||||
table
|
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 = Helpers.deepGet(initialValues, field) ?? defaultValue
|
let initialValue = Helpers.deepGet(initialValues, field) ?? defaultValue
|
||||||
|
@ -164,7 +167,7 @@
|
||||||
// If this field has already been registered and we previously had an
|
// 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
|
// error set, then re-run the validator to see if we can unset it
|
||||||
if (fieldState.error) {
|
if (fieldState.error) {
|
||||||
initialError = validator(initialValue)
|
initialError = validator?.(initialValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +257,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update field state
|
// Update field state
|
||||||
const error = validator ? validator(value) : null
|
const error = validator?.(value)
|
||||||
fieldInfo.update(state => {
|
fieldInfo.update(state => {
|
||||||
state.fieldState.value = value
|
state.fieldState.value = value
|
||||||
state.fieldState.error = error
|
state.fieldState.error = error
|
||||||
|
@ -288,12 +291,14 @@
|
||||||
|
|
||||||
// Create new validator
|
// Create new validator
|
||||||
const schemaConstraints = schema?.[field]?.constraints
|
const schemaConstraints = schema?.[field]?.constraints
|
||||||
const validator = createValidatorFromConstraints(
|
const validator = disableValidation
|
||||||
schemaConstraints,
|
? null
|
||||||
validationRules,
|
: createValidatorFromConstraints(
|
||||||
field,
|
schemaConstraints,
|
||||||
table
|
validationRules,
|
||||||
)
|
field,
|
||||||
|
table
|
||||||
|
)
|
||||||
|
|
||||||
// Update validator
|
// Update validator
|
||||||
fieldInfo.update(state => {
|
fieldInfo.update(state => {
|
||||||
|
|
Loading…
Reference in New Issue