react antd form rules 新增離焦事件

落花看风雪發表於2024-08-07
<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"

相關文章