truckingsim / Ajax-Bootstrap-Select

This uses the bootstrap-select plugin and extends it so that you can use a remote source to search.
MIT License
280 stars 97 forks source link

behaviour on close / reopen #180

Closed GuilhemSempere closed 10 months ago

GuilhemSempere commented 4 years ago

I'm using a multiple select and find it odd that after closing / reopening the widget the previously typed text disappears from the search input, whereas the items which matched that search are still available in the list below it. Is there any option to make it more consistent?

Bitz commented 4 years ago

I am having this same issue.

It looks like clearOnEmpty is not being obeyed for some reason.

I did the following to replicate clearing the items,

$('select').selectpicker('deselectAll');
$('select').find('[value]').remove();
$('select').selectpicker('refresh');
GuilhemSempere commented 10 months ago

Our issues are different. I was only mentioning the lookup results under the divider line, not being removed after closing/re-opening the widget

Anyway... 4 years later, I finally spent some time on this problem and solved it this way:

    $('#VariantIds button.dropdown-toggle').on('click', function() {
        if ($('#VariantIds ul li.selected').length == 0)
            $('#VariantIds ul li').remove();
        else
            $('#VariantIds ul li:gt(0):not(.selected)').remove();
    });

(VariantIds is just a div wrapping the selectpicker)