Bootstrap-3-Typeahead
Bootstrap-3-Typeahead copied to clipboard
Bootstrap 4.1 - Call to Undefined Function toLowerCase()
We recently upgraded our code base to Bootstrap 4.1 and Bootstrap 3 Typeahead stopped working. The issue was on line 214 where toLowerCase() is called on the variable 'it'. (This may also be an issue on line 225).
As a quick patch to get our site working again, I simply converted the 'it' variable to a string using the String() function. For example, the matcher method now reads:
matcher: function (item) {
var it = this.displayText(item);
return ~String(it).toLowerCase().indexOf(this.query.toLowerCase());
},
Hope this helps.
I was also able to fix this issue by sending in my own displayText function as an option. I think the problem may be that the current displayText method was not returning a string, which caused the matcher function to fail.
README file's displayText description: Method used to get textual representation of an item of the sources. Accepts a single argument item and has the scope of the typeahead instance. Should return a String.
Current displayText method:
displayText: function (item) {
return typeof item !== 'undefined' && typeof item.name != 'undefined' ? item.name : item;
},