bootstrap typeahead - changing source

Tzury Bar Yochay picture Tzury Bar Yochay · Nov 26, 2012 · Viewed 17.1k times · Source

I looking for a way to change source for typeahed.

For instance, assume I have the following 2 lists, and depend on the case, I'd like to have the typeahead workingin with a different source.

var list1 = ["this", "is", "first", "list"],
    list2 = ["second", "list", "comes", "here"];

$("selector").typeahead({source: list1})

Then, when I do

$("selector").typeahead({source: list2})

and start typing into the input box, the first list appears underneath the new one.

I tried doing

$("selector")
    .removeData()
    .typeahead({source: list2})

Yet, it has no effect.

Answer

Samuel Caillerie picture Samuel Caillerie · Nov 26, 2012

You have to update the data field associated as indicated here :

$("selector").data('typeahead').source = list2;