By doing that, we are always autocompleting the smallest possible option, avoiding errors in compound city names, for example.
My case
User wants to type "Salvador" (city in Brazil)
My DataSource array:
["são Paulo", "salvador do Sul", "macapa", "salvador"]
Problem:
Salvador do sul is autocompleted instead of Salvador because it goes first in the array, and since Salvador has less characters, it will never autocomplete.
Solution
always filter datasource from the smallest string to the biggest, so every single string will have the chance to be autocompleted
By doing that, we are always autocompleting the smallest possible option, avoiding errors in compound city names, for example.
My case
User wants to type "Salvador" (city in Brazil)
My DataSource array:
["são Paulo", "salvador do Sul", "macapa", "salvador"]
Problem:
Salvador do sul is autocompleted instead of Salvador because it goes first in the array, and since Salvador has less characters, it will never autocomplete.
Solution
always filter datasource from the smallest string to the biggest, so every single string will have the chance to be autocompleted