Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select2 val not reflecting the selection order but sorts it

I have been using this third party plugin by Ivan Vaynberg and have found an issue. While using multiselect in select2 I find that the select2("val") is returning the selected values in sorted order and is not reflecting the order of element selections although select2("data") does give the selections in order. Also it seems it is a reported bug in the github but strangely there has been no response from the third party. https://github.com/ivaynberg/select2/issues/1861

Is there anyone who has faced similar problem and has a solution for this?

Also is there anyway of implementing sortResults on select options with multiple attribute (multiselect basically) because it seems that sortResults only works for the input search bar provided in the single selects.

Thanks.

like image 901
Sourabh Avatar asked Nov 11 '22 16:11

Sourabh


1 Answers

I had tried various workaround but it seems the only way we can counter this for now is by making changes on the server side. What I did was to send the options as inputs (in order by appending an input every time an option is selected) in the form to the server side and process those inputs for the database. And as a result I got the options sorted on the client side when I made the request for the options again.

SortResults do work with multiple. I found out it later that my select was getting reinitialized by a redundant code which is why my sortResult attribute wasn't working.

like image 52
Sourabh Avatar answered Nov 14 '22 23:11

Sourabh