Skip to content

Instantly share code, notes, and snippets.

@eguven
Created July 27, 2012 10:40
Show Gist options
  • Save eguven/3187381 to your computer and use it in GitHub Desktop.
Save eguven/3187381 to your computer and use it in GitHub Desktop.
Twitter Bootstrap comma-separated typeahead
<script type="text/javascript">
jQuery(document).ready(function() {
$('#autocomplete').typeahead({
source: someDataSource
, matcher: function (item) {
queryItems = this.query.toLowerCase().split(/, */);
queryLast = queryItems[queryItems.length-1];
return ~item.toLowerCase().indexOf(queryLast)
}
, updater: function (item) {
items = this.query.toLowerCase().split(/, */);
items.pop();
items.push(item);
return items.join()
}
})
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment