Make form step number dynamic

This commit is contained in:
Andrew Kingston 2021-11-18 14:42:49 +00:00
parent 347a0d1d0f
commit 9f30599ec1
2 changed files with 6 additions and 2 deletions

View File

@ -23,13 +23,14 @@
// Register field with form
const formApi = formContext?.formApi
const labelPos = fieldGroupContext?.labelPosition || "above"
$: formStep = formStepContext ? $formStepContext || 1 : 1
$: formField = formApi?.registerField(
field,
type,
defaultValue,
disabled,
validation,
formStepContext || 1
formStep
)
// Focus label when editing

View File

@ -1,5 +1,6 @@
<script>
import { getContext, setContext } from "svelte"
import { writable } from "svelte/store"
import Placeholder from "../Placeholder.svelte"
export let step = 1
@ -9,7 +10,9 @@
const formContext = getContext("form")
// Set form step context so fields know what step they are within
setContext("form-step", step || 1)
const stepStore = writable(step || 1)
$: stepStore.set(step || 1)
setContext("form-step", stepStore)
$: formState = formContext?.formState
$: currentStep = $formState?.currentStep