nobleclem/jQuery-MultiSelect

onSelectAll( element, selected ) doesn't return correct list of what is selected

Closed this issue · 1 comments

My multiselect has option groups with selectGroup: true, so that I can (un)select all from an option group.

onSelectAll( element, selected ) callback returns selected as the correct number of selected options, but the element list is incorrect. It is always the full list and not just the options selected after un(selecting) an option group.

I worked around it by doing the following:

var previously_selected = JSON.parse(localStorage.getItem("selected"));
saveShow(); // function to save selected options to localstorage. The selected options are correct, even though element argument is not
var currently_selected = JSON.parse(localStorage.getItem("selected"));

Then I can diff the two to be able to show/hide divs based on changes to selected options.

The onSelectAll callback's first parameter is just the element of the <select> list. The second is the number of items selected. So if you wanted the values of the selected items all you would do is something like let currentValues = $(element).val()