JQuery Typeahead - Uncaught TypeError: Cannot read property 'name' from undefined
I am using Bootstrap-3 Typeahead plugin as well as Bootstrap Input Loading Plugin . I use it like this:
<input type="text" id="name" name="test" data-provide="typeahead">
And jQuery:
$.get('/design/assets/advertisements/countries.json', function(data) {
$("#name").typeahead({
source: data
});
$('#name').tagsinput({
typeahead: {
source: data
}
});
}, 'json');
However, type and tags work up to a point. Whenever I enter multiple words, I get suggestions, but whenever I select a sentence, no matter what I wrote, it will be added after entering the tag.
Example: If I write " Bah
" and select " Bahamas
" it looks like this: (Where would I think it will remove "Ba")
I am getting this error - I don't know if this was the reason:
Uncaught TypeError: Cannot read property 'name' of undefined
An error is thrown on this file: bootstrap3-typeahead.js
source to share
I downloaded the non-mined version of the bootstrap-3 typeahead plugin and changed this:
displayText: function(item) {
return item.name || item;
},
to that
displayText: function(item) {
if (typeof item == 'undefined') {
return '';
}
return item.name || item;
},
He solved the problem.
Actually, I don't know if this is a plugstrap-3 typeahead bug or some kind of incompatibility with the bootstrap bootstrap plugin I'm using.
source to share