Lex V
Lex V

Reputation: 1447

Using antd Tooltip within antd Form + ReactJs

I need to use antd Tooltip to show "Invalid Email!!",if I enter an invalid mail id. How to use it in ReactJS antd Form? The code I am using right now is:

<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>

How to modify this using antd Tooltip for showing the message?

I have tried another code with tooltip. But the issues are

The code is

<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>

Upvotes: 5

Views: 7722

Answers (1)

Triyugi Narayan Mani
Triyugi Narayan Mani

Reputation: 3109

You can use the visible property of tooltip as given below:

<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>

I have created a working demo.

Upvotes: 3

Related Questions