brianvoe / slim-select

Slim advanced select dropdown
http://slimselectjs.com
MIT License
1.07k stars 200 forks source link

Order not preserved using keepOrder and getSelected() #565

Closed pvictor closed 2 months ago

pvictor commented 2 months ago

Describe the bug Order is not preserved in select.getSelected() when using keepOrder: true

Recreate it in Codepen Here's a codepen to test: https://codepen.io/pvictor-r/pen/LYKMQPV?editors=1111

To Reproduce

HTML:

<script src="https://unpkg.com/slim-select@latest/dist/slimselect.min.js"></script>
<link href="https://unpkg.com/slim-select@latest/dist/slimselect.css" rel="stylesheet">
</link>

<select id="selectElement" multiple>
  <option>Option 1</option>
  <option>Option 2</option>
  <option>Option 3</option>
</select>
<button id="button" type="button">Click Me!</button>

JS:

var select = new SlimSelect({
  select: "#selectElement",
  settings: {
    keepOrder: true
  }
});
var button = document.getElementById("button");
button.addEventListener("click", function () {
  var values = select.getSelected();
  console.log(values);
});

Result: image

Am I missing something ? Thanks!

brianvoe commented 2 months ago

Nice find. I have a fix for it and will go out in the next release