1
- import { Button , Stack } from '@chakra-ui/react' ;
1
+ import {
2
+ Button ,
3
+ Code ,
4
+ ListItem ,
5
+ OrderedList ,
6
+ Stack ,
7
+ Text ,
8
+ } from '@chakra-ui/react' ;
2
9
import { zodResolver } from '@hookform/resolvers/zod' ;
3
10
import { useForm } from 'react-hook-form' ;
4
11
import { z } from 'zod' ;
@@ -39,7 +46,7 @@ const formSchema = () =>
39
46
}
40
47
} ) ;
41
48
42
- export const WithoutHook = ( ) => {
49
+ export const WithHook = ( ) => {
43
50
const form = useForm ( {
44
51
mode : 'onBlur' ,
45
52
resolver : zodResolver ( formSchema ( ) ) ,
@@ -50,9 +57,32 @@ export const WithoutHook = () => {
50
57
} ,
51
58
} ) ;
52
59
60
+ useWatchToTrigger ( { form, names : [ 'min' , 'default' , 'max' ] } ) ;
61
+
53
62
return (
54
63
< Form { ...form } >
55
64
< Stack >
65
+ < Text >
66
+ This is the story with the hook. You can find the story without the
67
+ hook below. Here is the scenario for maximal reproduction:
68
+ </ Text >
69
+ < OrderedList >
70
+ < ListItem >
71
+ Set the < Code > min</ Code > to 5
72
+ </ ListItem >
73
+ < ListItem > The validation is updated</ ListItem >
74
+ < ListItem >
75
+ Set the < Code > default</ Code > to 5.5
76
+ </ ListItem >
77
+ < ListItem >
78
+ The validation is updated even if the validation is on the{ ' ' }
79
+ < Code > min</ Code > field
80
+ </ ListItem >
81
+ < ListItem >
82
+ You have to go to the < Code > min</ Code > field to trigger the{ ' ' }
83
+ < Code > onBlur</ Code > event
84
+ </ ListItem >
85
+ </ OrderedList >
56
86
< FormField >
57
87
< FormFieldLabel > Min</ FormFieldLabel >
58
88
< FormFieldController
@@ -85,7 +115,7 @@ export const WithoutHook = () => {
85
115
) ;
86
116
} ;
87
117
88
- export const WithHook = ( ) => {
118
+ export const WithoutHook = ( ) => {
89
119
const form = useForm ( {
90
120
mode : 'onBlur' ,
91
121
resolver : zodResolver ( formSchema ( ) ) ,
@@ -96,11 +126,27 @@ export const WithHook = () => {
96
126
} ,
97
127
} ) ;
98
128
99
- useWatchToTrigger ( { form, names : [ 'min' , 'default' , 'max' ] } ) ;
100
-
101
129
return (
102
130
< Form { ...form } >
103
131
< Stack >
132
+ < Text >
133
+ This is the story without the hook. Here is the scenario for maximal
134
+ reproduction:
135
+ </ Text >
136
+ < OrderedList >
137
+ < ListItem >
138
+ Set the < Code > min</ Code > to 5
139
+ </ ListItem >
140
+ < ListItem > The validation is updated only on blur</ ListItem >
141
+ < ListItem >
142
+ Set the < Code > default</ Code > to 5.5
143
+ </ ListItem >
144
+ < ListItem >
145
+ The validation is not updated for the < Code > min</ Code > field, that
146
+ is because we are in the < Code > default</ Code > field. Even the blur
147
+ event will not trigger the validation.
148
+ </ ListItem >
149
+ </ OrderedList >
104
150
< FormField >
105
151
< FormFieldLabel > Min</ FormFieldLabel >
106
152
< FormFieldController
0 commit comments