I am using jquery auto complete to populate city names when user starts writing. These cities are from multiple countries and what I want to do now is to populate relevant cities if the user types in country name.
So for example if the user types in 'San'
jquery will populate the auto complete with ['San Diego','Santiago']
. Now if the user types in United States I want the auto complete to be populated with ['New York City', 'Boston', 'Seattle', 'San Diego', etc..]
.
What I can do is to create HashMap
with country as key and list of cities as value. Then I can just change the source of the auto complete appropriately whenever the input matches a country name.
$( "#citySearch" ).autocomplete({source: citySearchList});
Now the problem is displaying all options in the source even if United States
will not trigger ['New York', 'Boston', etc..]
in the normal implementation of autocomplete.
I tried using the trick in this answer