I may be using the wrong tools for this, so please recommend other approaches if they're appropriate. I'm fairly certain that my problem is in my typeahead method rather than the bloodhound method.
I need to search by personName, but populate personId for a form submission. I have a working controller method that passes the results as an array of hashes with id and name. A sample result looks like:
[{"1":"Nominee Employee"},{"2":"User Employee"}]
I can't find docs that address my need. I know that the bloodhound code is calling my controller method because the logs show the query happening. I just don't see anything that says 'here's how you get a specific attribute from a record to display.'
var names = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/employee/lastNameOptions?term=%QUERY',
wildcard: '%QUERY'
}
});
$('#bloodhound .typeahead').typeahead(null, {
name: 'names',
display: 'name',
source: names
});
I would expect the current implementation to at least try to print 1: Joe Schmo
but it's loading an empty dropdown box, so it must 'be aware' of results.
Thanks!