I'm trying to programmatically submit and ant design (v4.3.4) form with validation but form.validateFields()
always fails with outOfDate: true
if it is inside onValuesChange()
. (This form is a part of a larger form factory so I will eventually have to pass the form component to a props function which will then call submit.
const FormA = (props: StepProps) => {
const [form] = useForm();
return (
<Form
form={form}
name="form-a"
onValuesChange={async (changedValues, allValues) => {
form.validateFields().
then(values => console.log("PASSED").
catch(errorInfo => console.log("FAILED", errorInfo));
}}
>
<Form.Item
rules={[{ required: true }]}
name="item-a">
<Input />
</Form.Item>
<Form.Item
rules={[{ required: true }]}
name="item-b"
>
<Input />
</Form.Item>
<Form.Item
rules={[{ required: true }]}
name="item-c"
>
<Input />
</Form.Item>
</Form>
);
};
export default FormA;
I have called the form.validatedField()
function onValuesChange. I never get "PASSED" in the console, even when all inputs have values I always get 'FAILED' with the following errorInfo:
{
errorFields: []
outOfDate: true
values: { ..}
}
If I remove the form.validateFields() from onValuesChange
then it works fine.
I can't seem to figure out what is outOfDate
and why does validation always fail in onValuesChange function.