Semantic-UI icon indicating copy to clipboard operation
Semantic-UI copied to clipboard

[Dropdown] Input Order Should Reflect "Set Selected" Order

Open tmikaeld opened this issue 10 years ago • 14 comments

http://jsfiddle.net/czw7zy25/1/

The select order should reflect the "set selected" array order, it doesn't - instead it's listed in the order of the options.

This makes it very unpredictable, especially with sortSelect set to true.

tmikaeld avatar Mar 17 '16 10:03 tmikaeld

This same issue applies in the situation where the dropdown input has initial values, for example:

<input name="numbers" multiple type="hidden" value="162,16,136,129">

The dropdown will sort them in the order that they're provided in the markup. This is a problem where, for example, I want the dropdown choices to be alphabetically sorted, but I want the selection (e.g. values, labels) to be in the exact order that they're provided.

neutraali avatar May 27 '16 07:05 neutraali

Any workarounds to this issue?

brunotourinho avatar Mar 14 '17 15:03 brunotourinho

Any Update or workaround for this issue?

It is blocking to implement my requirement as well, where i need to get the selected values of multi select dropdown in the same order as user selected.

Thanks,

ponvino avatar Apr 15 '17 10:04 ponvino

The reason is due to this code which sets selected by iterating through the declared options and tests for matches against the set options.

A possible fix here would be to iterate through the set options and test for matches against the declared options instead.

staff0rd avatar May 03 '17 12:05 staff0rd

@staff0rd You are right, I've debugged the issue and the first part of the problem is that they loop the items instead of the passed values. Another issue is that the jquery add method which is used adds values in the order that they appear in the dom.

I could try to add a pull request but I'm not really familiar with the code.

jogee avatar Jul 05 '17 21:07 jogee

Eventually worked around this, you can call the set selected if you first add or move the options to the select in the order that you want them to appear and then refresh the dropdown.

Not happy but it works: http://jsfiddle.net/czw7zy25/3/

jogee avatar Jul 12 '17 23:07 jogee

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 23 '18 10:02 stale[bot]

This bug is real. It needs a patch.

ngouy avatar Mar 06 '18 09:03 ngouy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 04 '18 10:06 stale[bot]

bump!

brunotourinho avatar Jun 04 '18 11:06 brunotourinho

This is a bug, especially for multiple search, when user input label the label moves to arbitrary position of label list

cashsun avatar Jun 20 '18 00:06 cashsun

I'm also working on something where the order of the selection is important and to be preserved. This is fine when the list is modified while the page is loaded, but when the dropdown is first rendered with an initial value, it reorders the item and displays them lexicographically sorted, as others have mentioned.

Note that the set selected workaround only works if there isn't already a default value.

FichteFoll avatar Nov 08 '18 17:11 FichteFoll

I worked around by set one by one value, not all in the array

huypn1106 avatar Nov 27 '20 08:11 huypn1106

@huypn1106 Yeah, there are some workarounds that work... but it shouldn't be needed.

I'm going to switch away from semantic and fomantic, nothing is being updated and pull requests are not being merged.

tmikaeld avatar Nov 27 '20 08:11 tmikaeld