Choices.js: How to display selected choices in original order?

2.6k Views Asked by At

By default, the selected choices are displayed in the field in the order they were selected. However, I would like them to always show in their hard-coded order.

Basically, Choices.js provides the shouldSort option to determine if the list of choices shows in its original order or in alphabetical order. But I would like the selected choices to have the same kind of option.

Is this possible?

2

There are 2 best solutions below

0
HeyImArt On

I also was looking for this solution, if anyone else needs it in the future.

shouldSort: false

This will disable the sorting feature of choices js and display it in the original order.

Example:

const selectColors = document.querySelector('.js-colors');
new Choices(selectColors, {
    searchEnabled: false,
    itemSelectText: '',
    shouldSort: false,
  });
0
Aaron Harker On

shouldSort orders the drop-down list, if you want to order the selected items it is shouldSortItems - which defaults to false.