JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/corejs-typeahead/1.2.1/typeahead.bundle.js"></script>
<input class="typeahead">
<button id="setval">
Set
</button>
JavaScript
var names = [
{ id: 100, name: 'name100'},
{ id: 101, name: 'name101'}
];
var bh = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: names
});
jQuery(".typeahead").typeahead({
highlight: false,
hint: false,
minLength: 2
},
{
name: 'test1',
display: 'name',
source: bh,
templates: {
empty: [
'<div class="empty-message">',
'not found',
'</div>'
].join('\n')
}
});
$("#setval").click(function(){
jQuery(".typeahead").typeahead('val', 101);
});