diff --git a/src/useForm.ts b/src/useForm.ts index 1be9f70d..7879cf85 100644 --- a/src/useForm.ts +++ b/src/useForm.ts @@ -787,6 +787,8 @@ export class FormStore { { name, value, + errors: [], + warnings: [], }, ]); }; diff --git a/tests/index.test.tsx b/tests/index.test.tsx index 7f7ef718..a9a0e740 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -996,4 +996,31 @@ describe('Form.Basic', () => { expect(formRef.current?.getFieldError('light')).toHaveLength(0); expect(formRef.current?.getFieldError('bamboo')).toHaveLength(0); }); + + it('setFieldValue should reset errors', async () => { + const formRef = React.createRef(); + + const Demo: React.FC = () => ( +
+ Promise.reject('No!') }]}> + + +
+ ); + + render(); + + // Mock error first + await act(async () => { + await formRef.current?.validateFields().catch(() => {}); + }); + expect(formRef.current?.getFieldError('light')).toHaveLength(1); + + // setFieldValue + await act(async () => { + formRef.current?.setFieldValue('light', 'Bamboo'); + await Promise.resolve(); + }); + expect(formRef.current?.getFieldError('light')).toHaveLength(0); + }); });