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

shared-form.ts

44 lines926 Bytes

1import { createValidator } from '@tanstack/solid-form'
2import z from 'zod'
3import { appFormOptions } from '../../hooks/form'
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: {
29 name: '',
30 },
31 step2: {
32 name: '',
33 },
34 },
35 validators: [
36 {
37 run: z.object({
38 step1: step1Schema,
39 step2: step2Schema,
40 }),
41 triggers: [],
42 },
43 ],
44})