Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do bootstrap tooltips not work in bootstrap modals?

My tooltips are working on the mainpage perfectly. In a modal which is generated later by an ajax call the tooltips won't work.

I have included the following code inside the generated modal (result of the ajax call).

To re-ini the tooltips

<script>
  $('.tooltips').tooltip();
</script>

In the html of the modal

  <button class="btn btn-lg default tooltips blue-madison" type="submit"
   name="O" data-container="body" data-placement="top" 
   data-original-title="THIS TEXT FOR TOOLTIPS">
     <i class="fa fa-industry blue-madison"></i> BUTTON1
   </button>

  <button class="btn btn-lg default tooltips green-jungle" type="submit" 
    name="P" data-container="body" data-placement="top"
    data-original-title="THIS TEXT FOR TOOLTIPS">
      <i class="fa fa-user green-jungle "></i> BUTTON2
  </button>

Why don't the tooltips show- what I'm doing wrong?

like image 618
4usolutions Avatar asked Oct 10 '16 14:10

4usolutions


4 Answers

If you are using react I had success with a different answer. All you have to do is give the parent container a ref and then in the overlayTrigger component you just have to pass in the ref as a param to the container.

import React, { Component } from 'react';
import { OverlayTrigger, Tooltip } from 'react-bootstrap';

class random extends Component {
  constructor(props) {
    super(props);
    this.ref= React.createRef()

  }

  render() {
    return (
      <div ref={this.ref}>
            <OverlayTrigger
              placement="top"
              container={this.ref}
              overlay={
                <Tooltip data-container="body">Some text</Tooltip>
              }
            >
              <span className="d-inline-block">
                <i className="mdi mdi-help-circle pointer"></i>
              </span>
            </OverlayTrigger>
      </div>
    );
  }
}
like image 159
syntactic Avatar answered Sep 25 '22 11:09

syntactic


The issue is because of the z-index of modal and tooltip. You can try this,

.tooltip {
    z-index: 100000000; 
}
like image 22
Dhaval Avatar answered Nov 18 '22 00:11

Dhaval


Probably it's because you should call $('.tooltips').tooltip(); after the modal's content have been inserted in the document.

Otherwise, please post a fiddle with your current code where we can test it.

like image 9
Gabriel Avatar answered Nov 18 '22 00:11

Gabriel


Maybe this helps someone: I had a case when needed with ajax to populate & display a bootstrap modal (render view) on click (calling showModal(url, event) below); bootstrap tooltip and also fengyuanchen/datepicker were unresponsive, so I managed to trigger them after detecting modal loading, like this:

    function showModal(url, event) {
    $.when(
        $.ajax({
            url: url,
            method: 'GET',
            success: function (data) {
                $('#modal-wrapper').html(data);
            }
        })
    ).then(function() {
        $('.loaded_modal').modal().on('shown.bs.modal', function() {
            $('[data-toggle="datepicker"]').datepicker({
                format: "dd/mm/yyyy",
                autoclose: true,
                todayHighlight: true,
                zIndex: 1070,
                container: '.modal'
            });
            $('.modal [data-toggle="tooltip"]').tooltip({trigger: 'hover'}); 
            // could also be on click {trigger: 'hover click'}
        });
    });
like image 1
Mariana Marica Avatar answered Nov 17 '22 23:11

Mariana Marica