gpt4 book ai didi

reactjs - 在 antd Form + ReactJs 中使用 antd Tooltip

转载 作者:行者123 更新时间:2023-12-03 14:18:10 30 4
gpt4 key购买 nike

如果我输入无效的邮件 ID,我需要使用 antd 工具提示显示“无效的电子邮件!!”。如何在ReactJS antd Form中使用它?我现在使用的代码是:

<div style={{'height': '40px','display':'flex'}}> 
<label style={{'width':'80px','paddingTop':'8px'}}>Main Email:</label>
<FormItem >
{getFieldDecorator('Email', {
initialValue: '',
rules: [{
type: 'email', message: 'The input is not valid E-mail!',
}],
})(
<Input placeholder="Main Email" style={{'width':'170px'}} onChange={(e)=>{e.preventDefault(); e.stopPropagation();
this.handleChange(0,e, 'Email')}} />
)}
</FormItem> </div>

如何使用 antd Tooltip 来修改它以显示消息?

我尝试了另一个带工具提示的代码。但问题是

  • 仅当“悬停”到文本框时才起作用
  • 即使我输入了正确的电子邮件,工具提示仍然存在

代码是

<div style={{'height': '40px','display':'flex'}}>  
<label style={{'width':'80px','paddingTop':'8px'}}>CC Email:</label>
<FormItem >
{getFieldDecorator('Cc', {
initialValue: '',
rules: [{
type: 'email'
},],
})(
<Tooltip title="The input is not valid Email">
<Input placeholder="CC Email" style={{'width':'170px'}} onChange={(e)=>{e.preventDefault(); e.stopPropagation();
this.handleChange(0,e, 'Cc')}} />
</Tooltip>
)}
</FormItem>
</div>

最佳答案

您可以使用visible工具提示的属性如下所示:

<FormItem>
{getFieldDecorator("userName", {
rules: [
{
type: "email",
message: (
<Tooltip
visible={true}
title="The input is not valid Email!"
/>
)
}
]
})(
<Input
prefix={<Icon type="user" style={{ color: "rgba(0,0,0,.25)" }} />}
placeholder="Email"
/>
)}
</FormItem>

我创建了一个working demo .

关于reactjs - 在 antd Form + ReactJs 中使用 antd Tooltip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53610142/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com