Can we get popovers to be dismissable in the same way as modals, ie. make them close when user clicks somewhere outside of them?
Unfortunately I can't just use real modal instead of popover, because modal means position:fixed and that would be no popover anymore. :(
demo: http://jsfiddle.net/nessajtr/yxpM5/1/
}
this is my solution for it.
We found out we had an issue with the solution from @mattdlockyer (thanks for the solution!). When using the selector property for the popover constructor like this...
...the proposed solution for BS3 won't work. Instead it creates a second popover instance local to its
$(this)
. Here is our solution to prevent that:As mentioned the
$(this).popover('hide');
will create a second instance due to the delegated listener. The solution provided only hides popovers which are already instanciated.I hope I could save you guys some time.
I came up with this: My scenario included more popovers on the same page, and hiding them just made them invisible and because of that, clicking on items behind the popover was not possible. The idea is to mark the specific popover-link as 'active' and then you can simply 'toggle' the active popover. Doing so will close the popover completely $('.popover-link').popover({ html : true, container: 'body' })
With bootstrap 2.3.2 you can set the trigger to 'focus' and it just works:
This has been asked before here. The same answer I gave then still applies:
I had a similar need, and found this great little extension of the Twitter Bootstrap Popover by Lee Carmichael, called BootstrapX - clickover. He also has some usage examples here. Basically it will change the popover into an interactive component which will close when you click elsewhere on the page, or on a close button within the popover. This will also allow multiple popovers open at once and a bunch of other nice features.
Just add this attribute to html element to close popover in next click.
reference from https://getbootstrap.com/docs/3.3/javascript/#popovers