P
P
Pashchuk Ilya2019-02-06 12:42:19
JavaScript
Pashchuk Ilya, 2019-02-06 12:42:19

How to get around trouble with opening bootstrap-select in bootstrap dropdown?

Look guys, I have a dropdown with bootstrap, I have a select customized into it through the bootstrap-select lib, and I have a problem, this select does not work out the norms, since we get this select is also done through the bootstrap dropdown, in general, I solved the problem so that the parent dropdown does not close and works inside the select like this:

$('[sub-dropdown]').on('click', function (e) {
        var target = $(e.target),
            $parent = target.parents('.bootstrap-select');

        if ($parent.length) {
            $parent.toggleClass('show');
            $parent.find('.dropdown-menu').toggleClass('show');
            $parent.find('select').selectpicker('refresh');
            
            e.stopPropagation();
            e.preventDefault();
        } else {
            $parent.removeClass('show');
            $parent.removeClass('.dropdown-menu')
        }
    });

but the following problem arises, the select is not opened properly, the positioning is not redefined as it should be according to the standard, and if you apply $parent.find('select').selectpicker('toggle'); then it works norms bootstrap-select (as it should be, classes are hung on it and positioning is determined), but alas, toggle closes the parent globally for everyone, what should I do?
I’ll say right away with bootstrap I use js through cdn, I take styles and with pure current those that I need and customize to fit my needs!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question