From 85557d395da836ae3054e87975b03f722044a48c Mon Sep 17 00:00:00 2001 From: Imad-Eddine Srairi Date: Fri, 7 Jul 2017 17:23:21 +0200 Subject: [PATCH] Reset previous selection When multi-select is called several times on the same 'select' HTML element (e.g. when this 'select' element is updated with fresh data from a database each time it is displayed), it is necessary to reset previous selections (if any) before processing current selected / unselected items, otherwise items that were in the class 'ms-selected' will remain in this class, and will therefore be (wrongly) displayed as selected. --- js/jquery.multi-select.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/js/jquery.multi-select.js b/js/jquery.multi-select.js index d71ca10..c251429 100644 --- a/js/jquery.multi-select.js +++ b/js/jquery.multi-select.js @@ -88,6 +88,11 @@ } var selectedValues = ms.find('option:selected').map(function(){ return $(this).val(); }).get(); + + // Make sure to deselected all previously selected item (if any) + // before selecting items that should be selected indeed. + that.deselect_all(); + that.select(selectedValues, 'init'); if (typeof that.options.afterInit === 'function') {