Search code examples
reactjsantdant-design-pro

Ant Design: Validating form fields w/custom validators


I'd like to use notifications to push form feedback, instead of the inline messaging. e.g.

<Form.Item label="Name">
  {getFieldDecorator("name", {
    rules: [
      {
        validator(rule, value, callback) {
          if (!value) {
            callback("Enter Your Name");

            // I'd like to use this instead:
            // notification.open({
            //   message: "Enter Your Name",
            //   description:
            //     'This is the content of the notification.',
            // })
          }

          callback();
        }
      }
    ]
  })(<Name />)}
</Form.Item>;

Is is possible to validate form fields and maintain the visual feedback (i.e. things like the border-color change), without the inline messaging?


Solution

  • You can do as you showed in your code and use css to hide error messages.

    display: none