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"