How to update the source Option in bootstrap-typeahead.js

Lorraine Bernard picture Lorraine Bernard · Nov 22, 2012 · Viewed 12.3k times · Source

I am using bootstrap-typeahead in order to allow multiple selection. Here is the demo.

The original code has been update by @Sherbrow Twitter bootstrap typeahead multiple values

My question is related to the following use case:
after inserting Alaska value, I would like to update the source not showing again Alaska value.
Any hints?

Answer

toxicate20 picture toxicate20 · Nov 22, 2012

I had the same problem and this one will save you a lot of time. I've updated your old jsFiddle with my code example. The basic thing is that you need to do

var autocomplete = $('input').typeahead();
autocomplete.data('typeahead').source = newSource;

Where newSource is the new array. Now you just need a function that adds or removes an element, or whatever you need to do with it.