Skip to content

Instantly share code, notes, and snippets.

@felipsmartins
Created May 27, 2016 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipsmartins/bdc4ee091a0f568e721628ee48f66966 to your computer and use it in GitHub Desktop.
Save felipsmartins/bdc4ee091a0f568e721628ee48f66966 to your computer and use it in GitHub Desktop.
var searcher = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'http://host.com/busca?q=%QUERY',
wildcard: '%QUERY'
}
});
var typeahead = $('input.typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
display: 'cpf',
source: searcher,
templates: {
empty: ['<div class="empty-message text-danger">', 'Nenhum CPF encontrado', '</div>'].join("\n"),
suggestion: function (data) {
var html = ['<div class="">', data.cpf, '</div>'];
return html.join("");
}
}
});
typeahead.on('typeahead:select', function(eventData, suggestion) {
$('input[name=cadernoId][type=hidden]').val(suggestion._id);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment