11<script setup lang="ts">
22import type { AddonInputPassword } from ' #components'
3- import { toTypedSchema } from ' @vee-validate/zod'
43import { Field , useForm } from ' vee-validate'
54
6- import { z } from ' zod'
5+ import * as z from ' zod'
76
87definePageMeta ({
98 layout: ' empty' ,
@@ -30,9 +29,9 @@ const passwordRef = ref<InstanceType<typeof AddonInputPassword>>()
3029
3130// This is the Zod schema for the form input
3231// It's used to define the shape that the form data will have
33- const zodSchema = z
32+ const validationSchema = z
3433 .object ({
35- email: z .string (). email (VALIDATION_TEXT .EMAIL_REQUIRED ),
34+ email: z .email (VALIDATION_TEXT .EMAIL_REQUIRED ),
3635 password: z .string ().min (8 , VALIDATION_TEXT .PASSWORD_LENGTH ),
3736 confirmPassword: z .string (),
3837 terms: z .boolean (),
@@ -42,21 +41,21 @@ const zodSchema = z
4241 // before the form is submitted
4342 if (passwordRef .value ?.validation ?.feedback ?.warning || passwordRef .value ?.validation ?.feedback ?.suggestions ?.length ) {
4443 ctx .addIssue ({
45- code: z . ZodIssueCode . custom ,
44+ code: ' custom' ,
4645 message: passwordRef .value ?.validation ?.feedback ?.warning || passwordRef .value .validation .feedback ?.suggestions ?.[0 ],
4746 path: [' password' ],
4847 })
4948 }
5049 if (data .password !== data .confirmPassword ) {
5150 ctx .addIssue ({
52- code: z . ZodIssueCode . custom ,
51+ code: ' custom' ,
5352 message: VALIDATION_TEXT .PASSWORD_MATCH ,
5453 path: [' confirmPassword' ],
5554 })
5655 }
5756 if (! data .terms ) {
5857 ctx .addIssue ({
59- code: z . ZodIssueCode . custom ,
58+ code: ' custom' ,
6059 message: VALIDATION_TEXT .TERMS_REQUIRED ,
6160 path: [' terms' ],
6261 })
@@ -65,15 +64,14 @@ const zodSchema = z
6564
6665// Zod has a great infer method that will
6766// infer the shape of the schema into a TypeScript type
68- type FormInput = z .infer <typeof zodSchema >
67+ type FormInput = z .infer <typeof validationSchema >
6968
70- const validationSchema = toTypedSchema (zodSchema )
71- const initialValues = {
69+ const initialValues: FormInput = {
7270 email: ' ' ,
7371 password: ' ' ,
7472 confirmPassword: ' ' ,
7573 terms: false ,
76- } satisfies FormInput
74+ }
7775
7876const { values, handleSubmit, isSubmitting } = useForm ({
7977 validationSchema ,
0 commit comments