File tree Expand file tree Collapse file tree 2 files changed +7
-12
lines changed Expand file tree Collapse file tree 2 files changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ const useAJVForm = <T extends Record<string, any>>(
136
136
return { isValid : false , data : null } ;
137
137
}
138
138
139
- if ( ! isFormValid ( state , initialStateRef . current ) ) {
139
+ if ( ! isFormValid ( state ) ) {
140
140
return { isValid : false , data : null } ;
141
141
}
142
142
@@ -155,21 +155,16 @@ const useAJVForm = <T extends Record<string, any>>(
155
155
) ;
156
156
} ;
157
157
158
- const isFormValid = (
159
- currentState : IState < T > ,
160
- initialState : IState < T > ,
161
- ) : boolean => {
158
+ const isFormValid = ( currentState : IState < T > ) : boolean => {
162
159
const hasErrors = Object . keys ( currentState ) . some (
163
160
( key ) => currentState [ key ] . error !== '' ,
164
161
) ;
165
162
166
- const formIsDirty = isFormDirty ( currentState , initialState ) ;
167
-
168
- return ! hasErrors && formIsDirty ;
163
+ return ! hasErrors ;
169
164
} ;
170
165
171
166
const isValid = useMemo ( ( ) => {
172
- return isFormValid ( state , initialStateRef . current ) ;
167
+ return isFormValid ( state ) ;
173
168
} , [ state ] ) ;
174
169
175
170
const isDirty = useMemo (
Original file line number Diff line number Diff line change @@ -126,7 +126,7 @@ describe('useAJVForm', () => {
126
126
expect ( validation . isValid ) . toBe ( true ) ;
127
127
} ) ;
128
128
129
- it ( 'isValid should be false when the initial state is set or when reset is called' , ( ) => {
129
+ it ( 'isValid should be true when the initial state is set or when reset is called' , ( ) => {
130
130
const initialData = { title : 'Foo' } ;
131
131
const schema : JSONSchemaType < { title : string } > = {
132
132
type : 'object' ,
@@ -138,15 +138,15 @@ describe('useAJVForm', () => {
138
138
139
139
const { result } = renderHook ( ( ) => useAJVForm ( initialData , schema ) ) ;
140
140
141
- expect ( result . current . validate ( ) . isValid ) . toBe ( false ) ;
141
+ expect ( result . current . validate ( ) . isValid ) . toBe ( true ) ;
142
142
143
143
result . current . set ( { title : 'Bar' } ) ;
144
144
145
145
expect ( result . current . validate ( ) . isValid ) . toBe ( true ) ;
146
146
147
147
result . current . reset ( ) ;
148
148
149
- expect ( result . current . validate ( ) . isValid ) . toBe ( false ) ;
149
+ expect ( result . current . validate ( ) . isValid ) . toBe ( true ) ;
150
150
} ) ;
151
151
152
152
it ( 'validates minLength and maxLength for title' , ( ) => {
You can’t perform that action at this time.
0 commit comments