Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,8 @@ export class FormStore {
{
name,
value,
errors: [],
warnings: [],
},
]);
};
Expand Down
27 changes: 27 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<FormRef>();

const Demo: React.FC = () => (
<Form ref={formRef}>
<Field name="light" rules={[{ validator: () => Promise.reject('No!') }]}>
<Input />
</Field>
</Form>
);

render(<Demo />);

// Mock error first
await act(async () => {
await formRef.current?.validateFields().catch(() => {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.catch(() => {}) 这点不写也可以吧

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think he wrote this to prevent it console.error when run test

});
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);
});
});
Loading