Adam Cook
Adam Cook

Reputation: 620

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

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?

Upvotes: 2

Views: 3293

Answers (2)

Aaron Harker
Aaron Harker

Reputation: 321

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

Upvotes: 0

HeyImArt
HeyImArt

Reputation: 538

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,
  });

Upvotes: 0

Related Questions