Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs Ant设计:使用自定义验证器验证表单字段_Reactjs_Antd_Ant Design Pro - Fatal编程技术网

Reactjs Ant设计:使用自定义验证器验证表单字段

Reactjs Ant设计:使用自定义验证器验证表单字段,reactjs,antd,ant-design-pro,Reactjs,Antd,Ant Design Pro,我想使用推送表单反馈,而不是内联消息。e、 g <Form.Item label="Name"> {getFieldDecorator("name", { rules: [ { validator(rule, value, callback) { if (!value) { callback("Enter Your Name"); // I'd like to use thi

我想使用推送表单反馈,而不是内联消息。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>;

是否可以在不使用内联消息的情况下验证表单字段并维护视觉反馈,如边框颜色更改?

您可以使用this.props.form.setFields抛出自定义错误消息


您可以按照代码中显示的操作,并使用css隐藏错误消息

display: none

太明显了。我很惭愧这不是我事先考虑过的事情。显示:没有一个解决了我眼前的问题,但打破了布局。可见性:隐藏是一个更好的解决方案,但我也不喜欢。将您的答案标记为选定答案,直到提供更好的答案。
display: none