【问题标题】:Using antd Tooltip within antd Form + ReactJs在 antd Form + ReactJs 中使用 antd Tooltip
【发布时间】:2019-05-05 17:08:52
【问题描述】:

如果我输入了无效的邮件ID,我需要使用antd Tooltip显示“无效的电子邮件!!”。 如何在 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>

【问题讨论】:

  • 您好,请提供最低限度的复制品

标签: reactjs tooltip antd


【解决方案1】:

您可以使用工具提示的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

【讨论】:

  • 是的,但我需要电子邮件的工具提示,即,我想在页面中显示工具提示,直到我输入正确的电子邮件,如果我输入 a@,则应该显示工具提示,如果工具提示需要当我完全输入 a@gmail.com 时,应该禁用工具提示
  • 这是需要
  • 您能否为单击提交按钮时显示验证消息的情况创建演示代码?您编辑了该代码演示。现在我不能参考。我需要其他页面的逻辑。 @Triyugi Narayan Mani
猜你喜欢
  • 2021-02-02
  • 1970-01-01
  • 1970-01-01
  • 2018-01-11
  • 1970-01-01
  • 1970-01-01
  • 2021-05-16
  • 2020-08-07
  • 2019-07-05
相关资源
最近更新 更多