@@ -952,7 +952,7 @@ describe('Form.Basic', () => {
952952 } ) ;
953953 } ) ;
954954
955- it ( 'setFieldValue should always set touched' , async ( ) => {
955+ it ( 'setFieldsValue should always set touched' , async ( ) => {
956956 const EMPTY_VALUES = { light : '' , bamboo : [ ] } ;
957957 const formRef = React . createRef < FormRef > ( ) ;
958958
@@ -997,6 +997,35 @@ describe('Form.Basic', () => {
997997 expect ( formRef . current ?. getFieldError ( 'bamboo' ) ) . toHaveLength ( 0 ) ;
998998 } ) ;
999999
1000+ // https://github.com/ant-design/ant-design/issues/53981
1001+ it ( 'setFieldValue should mark the registered fields as touched' , async ( ) => {
1002+ const formRef = React . createRef < FormRef > ( ) ;
1003+
1004+ const Demo : React . FC = ( ) => (
1005+ < Form ref = { formRef } >
1006+ < Field name = "light" rules = { [ { required : true } ] } >
1007+ < Input />
1008+ </ Field >
1009+ </ Form >
1010+ ) ;
1011+
1012+ render ( < Demo /> ) ;
1013+
1014+ // Mock error first
1015+ await act ( async ( ) => {
1016+ await formRef . current ?. validateFields ( ) . catch ( ( ) => { } ) ;
1017+ } ) ;
1018+ expect ( formRef . current ?. getFieldError ( 'light' ) ) . toHaveLength ( 1 ) ;
1019+ expect ( formRef . current ?. isFieldTouched ( 'light' ) ) . toBeFalsy ( ) ;
1020+
1021+ await act ( async ( ) => {
1022+ formRef . current ?. setFieldValue ( 'light' , 'Bamboo' ) ;
1023+ await Promise . resolve ( ) ;
1024+ } ) ;
1025+ expect ( formRef . current ?. getFieldError ( 'light' ) ) . toHaveLength ( 0 ) ;
1026+ expect ( formRef . current ?. isFieldTouched ( 'light' ) ) . toBeTruthy ( ) ;
1027+ } )
1028+
10001029 it ( 'setFieldValue should reset errors' , async ( ) => {
10011030 const formRef = React . createRef < FormRef > ( ) ;
10021031
0 commit comments