-1

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?

Wilhelm
  • 1,407
  • 5
  • 16
  • 32

2 Answers2

1

You can throw custom error message using this.props.form.setFields

this.props.form.setFields({
  user: {
    value: values.user,
    errors: [new Error('forbid ha')],
  },
});

Reference for form.setFields

sathish kumar
  • 1,477
  • 1
  • 11
  • 18
1

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

display: none
Zohaib Ijaz
  • 21,926
  • 7
  • 38
  • 60
  • So obvious. I'm ashamed it wasn't something I considered beforehand. – Wilhelm May 17 '19 at 05:50
  • `display: none` solves my immediate problem but breaks the layout. `visibility: hidden` is a better solution but I'm not fond of either. Will mark yours as the selected answer, until a better one is offered. – Wilhelm May 17 '19 at 06:13