Answer the question
In order to leave comments, you need to log in
How to auto hide bootstrap popover so it doesn't hide later popovers?
Hello. I have a form with filters. When changing values, I want to display a popover with a "Go" button that hides after 4 seconds. The problem is shown if to change values of the form more often than in 4 seconds. The old popover disappears, a new popover appears for a fraction of a second and immediately disappears.
Here is my code:
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
$('.filter__entity input, .filter__entity select').on('change keypress keydown', debounce(
function(){
//$('.filter__entity').popover('hide');
$filterForm = $('*[data-role=filter-form]');
action = $filterForm.attr('action');
data = $filterForm.serialize();
console.log(data);
$(this).parents('.filter__entity').popover('destroy');
$(this).parents('.filter__entity').popover({
'content': '<a href="' + action + '?' + data + '" class="filter__submit button" style="margin: 1em;">Подобрать</a>',
'html': true,
'delay': { 'show': 300, 'hide': 100, },
}).popover('show');
// autohiding
$('.filter__entity').on('shown.bs.popover', function() {
var $pop = $(this);
setTimeout(function () {
$pop.popover('hide');
}, 4000);
});
}, 300)
);
Answer the question
In order to leave comments, you need to log in
You do not need to destroy the old popover, but check for its presence, and if it has not disappeared yet, increase the timeout.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question