From 690b3efddc10ac718c2899fd2b96e1cb504285e4 Mon Sep 17 00:00:00 2001 From: Kyle Date: Fri, 22 Jul 2016 15:54:11 -0700 Subject: [PATCH] Add: populate and sort function. Allowed for me to manually set sort index of values and have them be populated in the dual list box correctly. The goal behind this change was so users can choose a particular series of elements from the list and post them to the server, if there was an error then the model would be returned and the chosen elements would end up back in the desired order if the developer manually added the 'data-sortindex' attribute to the chosen elements in the correct order, then called the populate and sort method. --- src/jquery.bootstrap-duallistbox.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/jquery.bootstrap-duallistbox.js b/src/jquery.bootstrap-duallistbox.js index d94d4ae..d5c97dc 100644 --- a/src/jquery.bootstrap-duallistbox.js +++ b/src/jquery.bootstrap-duallistbox.js @@ -746,6 +746,19 @@ this.element.show(); $.data(this, 'plugin_' + pluginName, null); return this.element; + }, + populateAndSort: function (some_sortIndex) { + refreshSelects(this); + + if (this.settings.sortByInputOrder) { + sortOptionsByInputOrder(this.elements.select2); + } else { + sortOptions(this.elements.select2); + } + + if (some_sortIndex != null) { + this.sortIndex = some_sortIndex; + } } };