@@ -38,102 +38,129 @@ const zodFormSchema = z.object({
38
38
// },
39
39
// })
40
40
// ),
41
- // username: z
42
- // .string({
43
- // required_error: "Username is required.",
44
- // })
45
- // .min(2, {
46
- // message: "Username must be at least 2 characters.",
47
- // })
48
- // .superRefine(
49
- // fieldConfig({
50
- // description: "You cannot change this later.",
51
- // })
52
- // ),
53
-
54
- // password: z
55
- // .string({
56
- // required_error: "Password is required.",
57
- // })
58
- // .describe("Your secure password")
59
- // .min(8, {
60
- // message: "Password must be at least 8 characters.",
61
- // })
62
- // .superRefine(
63
- // fieldConfig({
64
- // description: (
65
- // <>
66
- // Always use a <b>secure password</b>!
67
- // </>
68
- // ),
69
- // inputProps: {
70
- // type: "password",
71
- // },
72
- // })
73
- // ),
74
-
75
- // favouriteNumber: z
76
- // .number({
77
- // invalid_type_error: "Favourite number must be a number.",
78
- // })
79
- // .min(1, {
80
- // message: "Favourite number must be at least 1.",
81
- // })
82
- // .max(10, {
83
- // message: "Favourite number must be at most 10.",
84
- // })
85
- // .default(1)
86
- // .optional(),
87
-
41
+ username : z
42
+ . string ( {
43
+ required_error : "Username is required." ,
44
+ } )
45
+ . min ( 2 , {
46
+ message : "Username must be at least 2 characters." ,
47
+ } )
48
+ . superRefine (
49
+ fieldConfig ( {
50
+ description : "You cannot change this later." ,
51
+ } )
52
+ ) ,
53
+ password : z
54
+ . string ( {
55
+ required_error : "Password is required." ,
56
+ } )
57
+ . describe ( "Your secure password" )
58
+ . min ( 8 , {
59
+ message : "Password must be at least 8 characters." ,
60
+ } )
61
+ . superRefine (
62
+ fieldConfig ( {
63
+ description : (
64
+ < >
65
+ Always use a < b > secure password</ b > !
66
+ </ >
67
+ ) ,
68
+ inputProps : {
69
+ type : "password" ,
70
+ } ,
71
+ } )
72
+ ) ,
73
+ favouriteNumber : z
74
+ . number ( {
75
+ invalid_type_error : "Favourite number must be a number." ,
76
+ } )
77
+ . min ( 1 , {
78
+ message : "Favourite number must be at least 1." ,
79
+ } )
80
+ . max ( 10 , {
81
+ message : "Favourite number must be at most 10." ,
82
+ } )
83
+ . default ( 1 )
84
+ . optional ( ) ,
88
85
acceptTerms : z
89
86
. boolean ( )
90
87
. describe ( "Accept terms and conditions." )
91
88
. refine ( ( value ) => value , {
92
89
message : "You must accept the terms and conditions." ,
93
90
path : [ "acceptTerms" ] ,
94
91
} ) ,
95
-
96
- // sendMeMails: z
97
- // .boolean()
98
- // .optional()
99
- // .superRefine(
100
- // fieldConfig({
101
- // fieldWrapper: (props: FieldWrapperProps) => {
102
- // return (
103
- // <>
104
- // {props.children}
105
- // <p className="text-muted-foreground text-sm">
106
- // Don't worry, we only send important emails!
107
- // </p>
108
- // </>
109
- // );
110
- // },
111
- // })
112
- // ),
113
-
114
- // birthday: z.coerce.date().optional(),
115
-
116
- // color: z.enum(["red", "green", "blue"]).optional(),
117
-
118
- // // Another enum example
119
- // marshmallows: z
120
- // .enum(["not many", "a few", "a lot", "too many"])
121
- // .describe("How many marshmallows fit in your mouth?"),
122
-
123
- // // Native enum example
124
- // sports: z.nativeEnum(Sports).describe("What is your favourite sport?"),
125
-
126
- // guests: z.array(
127
- // z.object({
128
- // name: z.string().optional(),
129
- // age: z.coerce.number().optional(),
130
- // })
131
- // ),
132
-
92
+ sendMeMails : z
93
+ . boolean ( )
94
+ . optional ( )
95
+ . superRefine (
96
+ fieldConfig ( {
97
+ fieldWrapper : ( props : FieldWrapperProps ) => {
98
+ return (
99
+ < >
100
+ { props . children }
101
+ < p className = "text-muted-foreground text-sm" >
102
+ Don't worry, we only send important emails!
103
+ </ p >
104
+ </ >
105
+ ) ;
106
+ } ,
107
+ } )
108
+ ) ,
109
+ birthday : z . coerce . date ( { message : "aaa" } ) . optional ( ) ,
110
+ color : z . enum ( [ "red" , "green" , "blue" ] ) . optional ( ) ,
111
+ // Another enum example
112
+ marshmallows : z
113
+ . enum ( [ "not many" , "a few" , "a lot" , "too many" ] )
114
+ . describe ( "How many marshmallows fit in your mouth?" ) ,
115
+ // Native enum example
116
+ sports : z . nativeEnum ( Sports ) . describe ( "What is your favourite sport?" ) ,
117
+ guests : z . array (
118
+ z . object ( {
119
+ name : z . string ( ) ,
120
+ age : z . coerce . number ( ) . optional ( ) ,
121
+ location : z . object ( {
122
+ city : z . string ( ) ,
123
+ country : z . string ( ) . optional ( ) ,
124
+ test : z . object ( {
125
+ name : z . string ( ) ,
126
+ age : z . number ( ) ,
127
+ test : z . object ( {
128
+ name : z . string ( ) ,
129
+ age : z . number ( ) ,
130
+ test : z . object ( {
131
+ name : z . string ( ) ,
132
+ age : z . number ( ) ,
133
+ test : z . object ( {
134
+ name : z . string ( ) ,
135
+ age : z . number ( ) ,
136
+ } ) ,
137
+ } ) ,
138
+ } ) ,
139
+ } ) ,
140
+ } ) ,
141
+ } )
142
+ ) ,
133
143
// location: z.object({
134
144
// city: z.string(),
135
145
// country: z.string().optional(),
146
+ // test: z.object({
147
+ // name: z.string(),
148
+ // age: z.number(),
149
+ // test: z.object({
150
+ // name: z.string(),
151
+ // age: z.number(),
152
+ // test: z.object({
153
+ // name: z.string(),
154
+ // age: z.number(),
155
+ // test: z.object({
156
+ // name: z.string(),
157
+ // age: z.number(),
158
+ // }),
159
+ // }),
160
+ // }),
161
+ // }),
136
162
// }),
163
+ // obj
137
164
} ) ;
138
165
139
166
export const zodSchemaProvider = new ZodProvider ( zodFormSchema ) ;
@@ -161,6 +188,7 @@ const yupFormSchema = object({
161
188
name : string ( ) . required ( ) ,
162
189
} )
163
190
) ,
191
+ abc : date ( ) . optional ( ) ,
164
192
sport : mixed ( ) . oneOf ( Object . values ( Sports ) ) ,
165
193
hobbies : array ( ) . of ( string ( ) ) ,
166
194
} ) ;
0 commit comments