R
R
Roman Fov2015-06-16 05:37:15
JavaScript
Roman Fov, 2015-06-16 05:37:15

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)
);


I believe that this is due to autohiding, which works for the second popover, although it should have worked for the first one.
Or $(this).parents('.filter__entity').popover('destroy'); works for created popover...

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Golubev, 2015-06-17
@wladyspb

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 question

Ask a Question

731 491 924 answers to any question