I use the Autocomplete Jorn Zaefferer plugin on several different pages. In both cases, the order of the displayed lines is a bit messed up.
Example 1: an array of strings: they are mostly in alphabetical order, with the exception of the general knowledge that was clicked at the top:
General knowledge, art and design, business research, citizenship, design and technology, English, geography, history, ICT, mathematics, MFL French, MFL German, MFL Spanish, Music, Physical Education, PSHE, Religious education, Something else
Displayed lines:
General knowledge, geography, art and design, business research, citizenship, design and technology, English, history, ICT, mathematics, MFL French, MFL German, MFL Spanish, Music, Physical Education, PSHE, Religious education, Something else
Note that geography has been transferred to the second subject after General Knowledge. The rest is all right.
Example 2: array of strings: as stated above, but with cross-curriculum instead of general knowledge.
Cross-educational institution, art and design, business research, citizenship, design and technology, English, geography, history, ICT, mathematics, MFL French, MFL German, MFL Spanish, Music, Physical Education, PSHE, Religious education, Science, What something else
Displayed lines:
Cross-textbook, citizenship, art and design, business studies, design and technology, English, geography, history, ICT, mathematics, MFL French, MFL German, MFL Spanish, music, physical education, PSHE, religious education, science, What something else
Here citizenship is pushed to position number 2.
I experimented a bit, and it seems that there is a mistake saying "to put things that begin with the same letter as the first element after the first element, and leave the rest alone." Type of hoax. I tried a bit of debugging by running warnings inside the autocomplete plugin code, but everywhere I see that it uses the correct order. it is like when it came to the conclusion that it went wrong.
Any ideas? Max
EDIT - response to Clint
Thank you for pointing to the corresponding bit of code. To simplify the diagnosis, I changed the array of values ββto ["carrot", "apple", "cherry"], which autofills, reorders ["carrot", "cherry", "apple"].
Here is the array that it generates for stMatchSets:
stMatchSets = ({'': [# 1 = {value: "carrot", data: "carrot"], result: "carrot"}, No. 3 = {value: "apple", data: ["apple"], result: "apple"}, # 2 = {value: "cherry", data: ["cherry"], result: "cherry"}], c: [# 1 #, # 2 #], a: [# 3 #]})
So, he collects the first letters together into a card, which makes sense as a strategy for matching the first step. However, I would like him to use this array of values, not a map, when it comes to populating the displayed list. I cannot understand what is happening with the cache inside the gut of the code (I am not very good at javascript).
SOLVED - I fixed this by cracking javascript in the plugin.
On line 549 (or 565), we return the csub variable, which is the object containing the corresponding data. Before it comes back, I will reorder it so that the order matches the original array of values ββthat we gave, i.e. We used to create the index in the first place, which I put in another variable:
csub = csub.sort (function (a, b) {return originalData.indexOf (a.value)> originalData.indexOf (b.value);})
hacky but it works. Personally, I believe that this behavior (possibly cleaner coding) should be the default behavior of the plugin: i.e. The order of the results should correspond to the original transmitted array of possible values. Thus, the user can sort their array alphabetically if they want (which is trivial) to get the results in alphabetical order, or they can save their own "custom" order.