0

I'm encountering a JavaScript error in my web application. I'm getting an "Uncaught TypeError: Cannot read properties of undefined (reading 'indexOf')" error on line 2 of vendor.bundle.base.js.

The call stack indicates the error might be originating from the addActiveClass function defined in template.js on line 16. This function seems to be using the indexOf method on a variable that's undefined.

Here's the relevant part of the call stack:

Uncaught TypeError: Cannot read properties of undefined (reading 'indexOf')
    at addActiveClass (template.js:16:33)
    at HTMLAnchorElement.<anonymous> (template.js:41:7)
    at Function.each (vendor.bundle.base.js:2:2976)
    at S.fn.init.each (vendor.bundle.base.js:2:1454)
    at HTMLDocument.<anonymous> (template.js:39:29)
    at e (vendor.bundle.base.js:2:30005)
    at t (vendor.bundle.base.js:2:30307)

Code Snippets:

 var masterTagSearchUrl = '@Url.Action("FindSteelTags", "Session")';
 $('#ScannedCoil_TagNo').typeahead({
     source: function (typeahead, query) {
         $.ajax({
             url: masterTagSearchUrl,
             type: "POST",
             data: { searchText: request, maxResults: 10, classCodeId: 0 },
             dataType: "JSON",
             async: false,
             success: function (results) {
                 var manufacturers = new Array;
                 $.map(results, function (data, item) {
                     var group;
                     group = {
                         SteelId: data.SteelId,
                         TagNumber: data.TagNumber
                     };
                     manufacturers.push(group);
                 });
                 typeahead.process(manufacturers);
             }
         });
     },
     property: 'name', 
     onselect: function (obj) {

     }
 });

I'm trying to implement a real-time typeahead functionality where suggestions appear as the user types in a search bar. This error seems to be preventing that functionality from working correctly.

4
  • what has this question to do with bootstrap or html? Also, it missing debugging details. Note that the errors often are not where they are noticed. When the error is noted by the debugger in line 16 then the error can be right before it.
    – tacoshy
    Commented Jun 7 at 13:07
  • Cannot read properties of undefined means the item it's trying to read from is undefined, eg xxx.indexOf -> xxx is undefined. If this is happening in a third-party library then you'll have to debug it. It sounds like the data being returned isn't in the format the library expects.
    – fdomn-m
    Commented Jun 7 at 14:32
  • @fdomn-m question modified
    – tech
    Commented Jun 10 at 4:04
  • Could you provide a link to template.js? Is that your code or is there eg a github site for it?
    – fdomn-m
    Commented Jun 10 at 9:10

0