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