Reputation: 493
I have multiple popovers on a single page, and they've all got a dismiss button in them.
If I dismiss the popover by clicking on the same button that opened it, I don't have a problem. The problem comes in when I click on one of the dismiss buttons in the popover.
When I click on the dismiss button in the popover, the popover closes, but the very next time I click to open it, it doesn't open. It only opens if I click on the button a second time.
HTML:
<button type="button" class="btn btn-default" data-toggle="popover" data-placement="right" data-content="<div class="clearfix"><div class="btn-group"><button class="btn btn-success btn-sm">Yes</button><button class="btn btn-default btn-sm close-popover" data-dismiss="popover" >No</button></div></div></div>" title="Delete this">Delete this</button>
JS:
$.fn.extend({
popoverClosable: function (options) {
var defaults = {
html: true,
template:
'<div class="popover">\
<div class="arrow"></div>\
<div class="popover-header">\
<button type="button" class="close" data-dismiss="popover" aria-hidden="true">×</button>\
<h3 class="popover-title"></h3>\
</div>\
<div class="popover-content"></div>\
</div>'
};
options = $.extend({}, defaults, options);
var $popover_togglers = this;
$popover_togglers.popover(options);
$popover_togglers.on('click', function (e) {
e.preventDefault();
$popover_togglers.not(this).popover('hide');
});
$('html').on('click', '[data-dismiss="popover"]', function (e) {
$popover_togglers.popover('hide');
});
}
});
$(function () {
$('[data-toggle="popover"]').popoverClosable();
});
How can I make my popover open every time I click the button to open it?
Upvotes: 4
Views: 1087
Reputation: 79630
Looks like a bug in 3.3.5. See https://github.com/twbs/bootstrap/issues/16732
I've worked around it with:
if ($.fn.popover.Constructor.VERSION == "3.3.5") {
$('[data-toggle="popover"]').on("hidden.bs.popover", function() {
$(this).data("bs.popover").inState.click = false
})
}
Upvotes: 5