I'm struggling to call typeahead.js functions like val , open , close , etc.
Typeahead works correctly on the input element when it displays entries, but when I try to call any function of type head, I get this error:
Uncaught Error: one of local, prefetch, or remote is requiredmessage: "one of local, prefetch, or remote is required
My initialization code is as follows:
var currentMedicalAid; var medicalAidList = $('#medicalAidList'); var medicalAidengine = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('MedicalAid1'), queryTokenizer: Bloodhound.tokenizers.whitespace, limit: 5, prefetch: { url: '/api/Search/GetMedicalAidList', } }); medicalAidengine.initialize(); medicalAidList.typeahead(null, { name: 'MedicalAid1', displayKey: 'MedicalAid1', // `ttAdapter` wraps the suggestion engine in an adapter that // is compatible with the typeahead jQuery plugin source: medicalAidengine.ttAdapter() }).blur(function () { match = false; for (var i = medicalAidengine.index.datums.length - 1; i >= 0; i--) { if ($(this).val() == medicalAidengine.index.datums[i].MedicalAid1) { currentMedicalAid = medicalAidengine.index.datums[i].MedicalAidID; match = true; } }; if (!match) { currentMedicalAid = '00000000-0000-0000-0000-000000000000'; $(this).val(''); medicalAidList.typeahead('val', ''); // throws error } });;
Every time I run one of these functions, I get an error message:
medicalAidList.typeahead('val', ''); or $('#medicalAidList').typeahead('val','');
Any help would be greatly appreciated.
thanks
source share