Open History to see the last commit
1import { createValidator } from '@tanstack/svelte-form'
2import { z } from 'zod'
3import { appFormOptions } from '../../hooks/form.js'
4β
5export const step1Schema = z.object({
6 name: z.string().min(2, 'Name must be at least 2 characters'),
7})
8β
9export const step2Schema = z.object({
10 name: z.string().min(3, 'Name must be at least 3 characters'),
11})
12β
13export const stepValidator = createValidator({
14 triggers: [
15 {
16 trigger: 'change',
17 when: ({ groupApi, formApi }) => {
18 const submitTries =
19 groupApi?.state.submissionAttempts ?? formApi.state.submissionAttempts
20 return submitTries > 0
21 },
22 },
23 ],
24})
25β
26export const wizardFormOpts = appFormOptions({
27 defaultValues: {
28 step1: { name: '' },
29 step2: { name: '' },
30 },
31 validators: [
32 {
33 run: z.object({
34 step1: step1Schema,
35 step2: step2Schema,
36 }),
37 triggers: [],
38 },
39 ],
40})