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...
<!-- 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">×</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 -->
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?
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.
$("[data-toggle=popover]").on("hide", function (e) {
e.stopPropagation();
});
solved the issue for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With