Add custom validation support to all fields except relationships

This commit is contained in:
Andrew Kingston 2021-08-10 14:37:14 +01:00
parent b4f51d44d5
commit 1b4a24fe83
8 changed files with 30 additions and 2 deletions

View File

@ -6,6 +6,7 @@
export let field
export let label
export let disabled = false
export let validation
let fieldState
let fieldApi
@ -35,6 +36,7 @@
{label}
{field}
{disabled}
{validation}
type="attachment"
bind:fieldState
bind:fieldApi
@ -44,6 +46,7 @@
<CoreDropzone
value={$fieldState.value}
disabled={$fieldState.disabled}
error={$fieldState.error}
on:change={e => {
fieldApi.setValue(e.detail)
}}

View File

@ -6,6 +6,7 @@
export let label
export let text
export let disabled = false
export let validation
let fieldState
let fieldApi
@ -15,6 +16,7 @@
{label}
{field}
{disabled}
{validation}
type="boolean"
bind:fieldState
bind:fieldApi

View File

@ -7,12 +7,21 @@
export let placeholder
export let disabled = false
export let enableTime = false
export let validation
let fieldState
let fieldApi
</script>
<Field {label} {field} {disabled} type="datetime" bind:fieldState bind:fieldApi>
<Field
{label}
{field}
{disabled}
{validation}
type="datetime"
bind:fieldState
bind:fieldApi
>
{#if fieldState}
<CoreDatePicker
value={$fieldState.value}

View File

@ -11,6 +11,7 @@
export let defaultValue
export let type
export let disabled = false
export let validation
// Get contexts
const formContext = getContext("form")
@ -21,7 +22,12 @@
// Register field with form
const formApi = formContext?.formApi
const labelPosition = fieldGroupContext?.labelPosition || "above"
const formField = formApi?.registerField(field, defaultValue, disabled)
const formField = formApi?.registerField(
field,
defaultValue,
disabled,
validation
)
// Expose field properties to parent component
fieldState = formField?.fieldState

View File

@ -6,6 +6,7 @@
export let label
export let placeholder
export let disabled = false
export let validation
let fieldState
let fieldApi
@ -15,6 +16,7 @@
{label}
{field}
{disabled}
{validation}
type="longform"
bind:fieldState
bind:fieldApi

View File

@ -7,6 +7,7 @@
export let placeholder
export let disabled = false
export let optionsType = "select"
export let validation
let fieldState
let fieldApi
@ -17,6 +18,7 @@
{field}
{label}
{disabled}
{validation}
type="options"
bind:fieldState
bind:fieldApi

View File

@ -9,6 +9,7 @@
export let label
export let placeholder
export let disabled = false
export let validation
let fieldState
let fieldApi
@ -64,6 +65,7 @@
{label}
{field}
{disabled}
{validation}
type="link"
bind:fieldState
bind:fieldApi

View File

@ -7,6 +7,7 @@
export let placeholder
export let type = "text"
export let disabled = false
export let validation
let fieldState
let fieldApi
@ -16,6 +17,7 @@
{label}
{field}
{disabled}
{validation}
type={type === "number" ? "number" : "string"}
bind:fieldState
bind:fieldApi