Support custom validation rules for ejected block fields (#12799)

This commit is contained in:
melohagan 2024-01-19 11:32:13 +00:00 committed by GitHub
parent 87be623057
commit af51a167a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 22 deletions

View File

@ -88,7 +88,7 @@
<BlockComponent <BlockComponent
type="form" type="form"
bind:id={formId} bind:id={formId}
props={{ dataSource, disableValidation: true }} props={{ dataSource, disableSchemaValidation: true }}
> >
{#if title || enrichedSearchColumns?.length || showTitleButton} {#if title || enrichedSearchColumns?.length || showTitleButton}
<BlockComponent <BlockComponent

View File

@ -147,7 +147,7 @@
bind:id={formId} bind:id={formId}
props={{ props={{
dataSource, dataSource,
disableValidation: true, disableSchemaValidation: true,
editAutoColumns: true, editAutoColumns: true,
size, size,
}} }}

View File

@ -14,7 +14,7 @@
// Not exposed as a builder setting. Used internally to disable validation // Not exposed as a builder setting. Used internally to disable validation
// for fields rendered in things like search blocks. // for fields rendered in things like search blocks.
export let disableValidation = false export let disableSchemaValidation = false
// Not exposed as a builder setting. Used internally to allow searching on // Not exposed as a builder setting. Used internally to allow searching on
// auto columns. // auto columns.
@ -103,7 +103,7 @@
{schema} {schema}
{table} {table}
{initialValues} {initialValues}
{disableValidation} {disableSchemaValidation}
{editAutoColumns} {editAutoColumns}
{currentStep} {currentStep}
> >

View File

@ -11,7 +11,7 @@
export let size export let size
export let schema export let schema
export let table export let table
export let disableValidation = false export let disableSchemaValidation = false
export let editAutoColumns = false export let editAutoColumns = false
// We export this store so that when we remount the inner form we can still // We export this store so that when we remount the inner form we can still
@ -156,17 +156,16 @@
if (!field) { if (!field) {
return return
} }
// Create validation function based on field schema // Create validation function based on field schema
const schemaConstraints = schema?.[field]?.constraints const schemaConstraints = disableSchemaValidation
const validator = disableValidation
? null ? null
: createValidatorFromConstraints( : schema?.[field]?.constraints
schemaConstraints, const validator = createValidatorFromConstraints(
validationRules, schemaConstraints,
field, validationRules,
table field,
) table
)
// Sanitise the default value to ensure it doesn't contain invalid data // Sanitise the default value to ensure it doesn't contain invalid data
defaultValue = sanitiseValue(defaultValue, schema?.[field], type) defaultValue = sanitiseValue(defaultValue, schema?.[field], type)
@ -332,15 +331,15 @@
const { value, error } = fieldState const { value, error } = fieldState
// Create new validator // Create new validator
const schemaConstraints = schema?.[field]?.constraints const schemaConstraints = disableSchemaValidation
const validator = disableValidation
? null ? null
: createValidatorFromConstraints( : schema?.[field]?.constraints
schemaConstraints, const validator = createValidatorFromConstraints(
validationRules, schemaConstraints,
field, validationRules,
table field,
) table
)
// Update validator // Update validator
fieldInfo.update(state => { fieldInfo.update(state => {