I am having a simple AntD Form with some field validation. I am expecting the error array to hold for example the required error when calling the getFieldsError function. But the returned error array is always empty eventhough when the error is shown inline in the UI.
const [form] = Form.useForm();
<Form className={otherProps.className} form={form}>
<Form.Item
name="name"
rules={[
{ required: true, message: 'A name is required!' },
() => ({
validator(_, value) {
if (!!items.find((item: Item) => item.name === value)) {
return Promise.reject(new Error('The name must be unique!'));
}
return Promise.resolve();
},
}),
]}
initialValue={itemForm.item.name}
>
<Input
value={itemForm.item.name}
placeholder="Item name"
onChange={(event: ChangeEvent<HTMLInputElement>) => {
form.setFieldsValue({ name: event.target.value });
console.log(form.getFieldsError());
}}
/>
</Form.Item>
</Form>