Skip to content

"Deselect All" doesn't consistently work with virtual scroll #2352

@chadrjohnson

Description

@chadrjohnson

Environment
Chrome (mac), 78.0.3904.87
jQuery 3.3.1
bootstrap 3.4.1
bootstrap-select 1.13.12
angularjs 1.7.8

First of all, thanks for providing and maintaining a great plugin. It provides a lot of nice functionality for us.

Here's an edge case I encountered.

I have a selectpicker with a lot of options (~2000) and virtual scroll enabled. And the options are dynamically updated based on the value of a second selectpicker.

I can reproduce the issue with the following:

  1. Search for and select options that are outside the current view.
  2. Update the options via the second selectpicker, but where the current selections are still valid.
  3. Clicking on the "Deselect All" button does not deselect the options.

If there are any selected options within the current updated view, "Deselect All" works as expected. If a new option is selected, "Deselect All" works as expected. If I search for the selected options and bring them into the view, "Deselect All" works as expected. It's only when the options are outside the current view, the options are updated and the selectpicker refreshed, that the "Deselect All" step fails.

I can fix the issue with a small change to the "changeAll" method. In the case above, the "previousSelected" count is unexpectantly zero. However, the "prevValue" array is correct and represents the correct selections from step #1 above.

If I change line 2715 from:

if (previousSelected === currentSelected) return;

to

if (prevValue.length === currentSelected) return;

"Deselect All" works as expected.

Looking more closely at the "previousSelected" count, it seems that it's not correct when some of the previously selected options are in the current view and some are not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions