Created
May 27, 2016 18:14
-
-
Save felipsmartins/bdc4ee091a0f568e721628ee48f66966 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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