File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -787,6 +787,8 @@ export class FormStore {
787
787
{
788
788
name,
789
789
value,
790
+ errors : [ ] ,
791
+ warnings : [ ] ,
790
792
} ,
791
793
] ) ;
792
794
} ;
Original file line number Diff line number Diff line change @@ -996,4 +996,31 @@ describe('Form.Basic', () => {
996
996
expect ( formRef . current ?. getFieldError ( 'light' ) ) . toHaveLength ( 0 ) ;
997
997
expect ( formRef . current ?. getFieldError ( 'bamboo' ) ) . toHaveLength ( 0 ) ;
998
998
} ) ;
999
+
1000
+ it ( 'setFieldValue should reset errors' , async ( ) => {
1001
+ const formRef = React . createRef < FormRef > ( ) ;
1002
+
1003
+ const Demo : React . FC = ( ) => (
1004
+ < Form ref = { formRef } >
1005
+ < Field name = "light" rules = { [ { validator : ( ) => Promise . reject ( 'No!' ) } ] } >
1006
+ < Input />
1007
+ </ Field >
1008
+ </ Form >
1009
+ ) ;
1010
+
1011
+ render ( < Demo /> ) ;
1012
+
1013
+ // Mock error first
1014
+ await act ( async ( ) => {
1015
+ await formRef . current ?. validateFields ( ) . catch ( ( ) => { } ) ;
1016
+ } ) ;
1017
+ expect ( formRef . current ?. getFieldError ( 'light' ) ) . toHaveLength ( 1 ) ;
1018
+
1019
+ // setFieldValue
1020
+ await act ( async ( ) => {
1021
+ formRef . current ?. setFieldValue ( 'light' , 'Bamboo' ) ;
1022
+ await Promise . resolve ( ) ;
1023
+ } ) ;
1024
+ expect ( formRef . current ?. getFieldError ( 'light' ) ) . toHaveLength ( 0 ) ;
1025
+ } ) ;
999
1026
} ) ;
You can’t perform that action at this time.
0 commit comments