Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 2.3.1 popover causing parent modal to close

I'm running into an issue where I'm displaying some data in a Bootstrap modal. This data contains an icon which I'm turning into a popover. When I hover over the icon, the popover displays and everything works correctly, but when I mouse away from the icon, not only does the popover close, but the parent modal closes also.

I think this is the same issue as described here. However, the posted solution does not work for me. I'm capturing the popover's "hidden" event, but neither setting e.cancelBubble = true or calling e.stopPropagation() stops the parent modal from closing.

I don't have my code in front of me at the moment, but here is a rough mockup based on my general recollection...

HTML


<!-- ko with: myFoo -->
<div class="modal hide fade" data-bind="visible: isOpen">
    <div class="modal-header">
        <button type="button" class="close" data-bind="click: close">&times;</button>
        <h3>Title Bar!</h3>
    </div>
    <div class="modal-body">
        <!-- dynamically generated modal content goes here, including... -->
        <table>
            <tr>
                <td data-bind="popover: $data">
                    <i class="icon-question-mark" data-content="la la la..." />
                </td>
            </tr>
        </table>
    </div>
    <div class="modal-footer">
        <a href="#" class="btn" data-bind="click: close">Close</a>
    </div>
</div>
<!-- /ko -->

Knockout Custom Binding Handler


ko.bindingHandlers.popover = {

    init: function(element)
    {
        $(element).children().andSelf().on("mousenter", "[data-content]"function() {
            var options = {...}
            $(this).popover(options).on("hidden", function(e) {
                e.cancelBubble = true;
                e.stopPropagation();
            });
        });
    }
};

Does anyone have any ideas / suggestions on how to fix this?

like image 775
Joshua Barker Avatar asked Jul 11 '13 22:07

Joshua Barker


2 Answers

Credit goes to afanasy who mentioned this as a comment:

$("[data-toggle=popover]").on("hidden", function (e) {
   e.stopPropagation();
});

note: 'hidden' instead of 'hide'. This is for bootstrap 2.3.2.

like image 53
DrewB Avatar answered Nov 11 '22 23:11

DrewB


$("[data-toggle=popover]").on("hide", function (e) {
    e.stopPropagation();
});

solved the issue for me

like image 23
Paweł Staniec Avatar answered Nov 12 '22 00:11

Paweł Staniec