Make form step number dynamic
This commit is contained in:
parent
c2bf1de547
commit
6e3044f7c9
|
@ -23,13 +23,14 @@
|
||||||
// Register field with form
|
// Register field with form
|
||||||
const formApi = formContext?.formApi
|
const formApi = formContext?.formApi
|
||||||
const labelPos = fieldGroupContext?.labelPosition || "above"
|
const labelPos = fieldGroupContext?.labelPosition || "above"
|
||||||
|
$: formStep = formStepContext ? $formStepContext || 1 : 1
|
||||||
$: formField = formApi?.registerField(
|
$: formField = formApi?.registerField(
|
||||||
field,
|
field,
|
||||||
type,
|
type,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
disabled,
|
disabled,
|
||||||
validation,
|
validation,
|
||||||
formStepContext || 1
|
formStep
|
||||||
)
|
)
|
||||||
|
|
||||||
// Focus label when editing
|
// Focus label when editing
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { getContext, setContext } from "svelte"
|
import { getContext, setContext } from "svelte"
|
||||||
|
import { writable } from "svelte/store"
|
||||||
import Placeholder from "../Placeholder.svelte"
|
import Placeholder from "../Placeholder.svelte"
|
||||||
|
|
||||||
export let step = 1
|
export let step = 1
|
||||||
|
@ -9,7 +10,9 @@
|
||||||
const formContext = getContext("form")
|
const formContext = getContext("form")
|
||||||
|
|
||||||
// Set form step context so fields know what step they are within
|
// 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
|
$: formState = formContext?.formState
|
||||||
$: currentStep = $formState?.currentStep
|
$: currentStep = $formState?.currentStep
|
||||||
|
|
Loading…
Reference in New Issue