react antd form rules 添加离焦事件

<Form.Item
  label="Name"
  name="name"
  validateTrigger="onBlur"
  rules={[
    { required: true, message: "Please input your name!" },
    {
      validator: checkName,
    },
  ]}
>
  <Input placeholder="Maximum 15 characters" maxLength={15} />
</Form.Item>
// 方法
  // 查看名称是否重复
  const checkName = (_: any, value: any) => {
    console.log(value);
    if (value) {
      return Promise.reject("重复");
    } else {
      return Promise.reject("");
    }
  };
validateTrigger="onBlur"
posted @ 2024-08-07 21:02  落花看风雪  阅读(17)  评论(0编辑  收藏  举报