Monday, 4 October 2021

How to use Antd InternalFormInstance to validate form without display of UI Errors

Trying to disable the form submit button till the validation is fully passed.

This is something a old ask, i have come across the threads regarding this topic.

Below thread rised helps to trigger validation without display of UI errors: https://github.com/ant-design/ant-design/issues/25993

The below code works within the hoc of my footer button wrapper, but it is verifying for all fields to be touched and even applicable for non-required fields which is not right and expected.

      <Form.Item shouldUpdate>
          {() => (
            <Button
              type="primary"
              htmlType="submit"
              disabled={
                !!form
                  .getFieldsError()
                  .filter(({ errors }) => errors.length).length
              }
            >
              Log in
            </Button>
          )}
        </Form.Item>

Unfortunately, https://github.com/ant-design/ant-design/issues/23281 thread is full of chinese and i cannot understand.

My existing form.validateFields refers to formInstance, but it is referring to: InternalFormInstance.

How to import this and validate? Is it really supported in antd 4 version?

Example code as a reference will be helpful!



from How to use Antd InternalFormInstance to validate form without display of UI Errors

No comments:

Post a Comment