Bootstrap-3-Typeahead icon indicating copy to clipboard operation
Bootstrap-3-Typeahead copied to clipboard

Bootstrap 4.1 - Call to Undefined Function toLowerCase()

Open ZacharyDraper opened this issue 6 years ago • 1 comments

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.

ZacharyDraper avatar Apr 19 '18 01:04 ZacharyDraper

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; },

caitlineatman avatar Jul 06 '18 14:07 caitlineatman