Fix issue with svelte reactive statements not being sufficiently 'reactive' in core form field in client lib by replacing with manual store subscription

This commit is contained in:
Andrew Kingston 2021-08-23 15:13:41 +01:00
parent 796dc24b06
commit 3fc345a8fe
1 changed files with 8 additions and 5 deletions

View File

@ -1,7 +1,7 @@
<script>
import Placeholder from "../Placeholder.svelte"
import FieldGroupFallback from "./FieldGroupFallback.svelte"
import { getContext } from "svelte"
import { getContext, onDestroy } from "svelte"
export let label
export let field
@ -31,10 +31,13 @@
formStepContext || 1
)
// Expose field properties to parent component
$: fieldState = $formField?.fieldState
$: fieldApi = $formField?.fieldApi
$: fieldSchema = $formField?.fieldSchema
// Update form properties in parent component on every store change
const unsubscribe = formField.subscribe(value => {
fieldState = value?.fieldState
fieldApi = value?.fieldApi
fieldSchema = value?.fieldSchema
})
onDestroy(unsubscribe)
// Keep validation rules up to date
$: updateValidation(validation)