Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

Step2Form.svelte

39 lines1.0 KB

1<script lang="ts">
2 import type { SvelteFormType } from '@tanstack/svelte-form'
3 import { step2Schema, stepValidator } from './shared-form.js'
4 import type { wizardFormOpts } from './shared-form.js'
5​
6 interface Props {
7 form: SvelteFormType<typeof wizardFormOpts>
8 step: number
9 setStep: (step: number) => void
10 }
11​
12 const { form, step, setStep }: Props = $props()
13</script>
14​
15<form.FormGroup
16 name="step2"
17 validators={[stepValidator(step2Schema)]}
18 onSubmit={async () => {
19 await form.handleSubmit()
20 }}
22 {#snippet children(formGroup)}
23 <form
24 onsubmit={(event) => {
25 event.preventDefault()
26 event.stopPropagation()
27 formGroup.handleSubmit()
28 }}
29 >
30 <formGroup.Field name="name">
31 {#snippet children(field)}
32 <field.TextField label="Step 2 Name" />
33 {/snippet}
34 </formGroup.Field>
35 <button type="button" onclick={() => setStep(step - 1)}>Back</button>
36 <form.SubscribeButton label="Submit" />
37 </form>
38 {/snippet}
39</form.FormGroup>