Skip to content

Instantly share code, notes, and snippets.

@ccorcos
Last active August 29, 2015 13:57
Show Gist options
  • Save ccorcos/9677078 to your computer and use it in GitHub Desktop.
Save ccorcos/9677078 to your computer and use it in GitHub Desktop.
Bootstrap 2 typeahead with Meteor
I spent way too long trying to get this to work.
Template.search.events({
'keyup input#search': function(e, t) {
if (e.keyCode == 13) {
// if the user presses enter to select a typeahead
var node = Nodes.findOne({
title: e.target.value
});
if (node) {
selectNodeOrLink("circle", node._id);
}
}
}
})
Template.search.rendered = function() {
// intialize bootstrap typeahead
var autocomplete = $('input#search').typeahead();
// autorun typeahead data source update
Deps.autorun(function() {
titles = function() {
return _.uniq(_.pluck(Nodes.find().fetch(), 'title'));
}
autocomplete.data("typeahead").source = titles();
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment