Search code examples
reactjsantd

React antd form disable submit button


How could I disable form submit button using antd

Form validations work, but I need to visually disable form submit button when validation fails

enter image description here

This is a stackblitz url https://stackblitz.com/edit/react-ts-z5d6tr?file=Hello.tsx


Solution

  • I found some elegant way to perform this

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