JSAPI - Getting "Type Error a.toLowerCase is not a function" with Search

622
2
08-27-2020 01:43 PM
Arne_Gelfert
Occasional Contributor III

So there is nothing worse, I find, than wanting to reuse some code you have successfully deployed in once place and not getting it work elsewhere. I'm running into this with using Search (JSAPI 3,x) in my latest custom widget for WAB 2.16.

It's a simple search with suggestions that I'm recycling. Gave it a new name and hooked it into a new service but it bombs when trying to return suggestions. This is what I'm doing, maybe someone spots my obvious mistake.

// plugged in the widget.html, I have

<div data-dojo-attach-point="searchWithSuggestions" id="searchWithSuggestions"></div>‍‍‍‍‍‍

Then I do this in Javascript...

// widget.js

startup : function() {
[ ... ]

var searchUrl = "https://.....Mapserver/1 ";

var searchSources = [
        {featureLayer: new FeatureLayer(searchUrl),
         name: 'Layer 1',
         outFields: ["*"],
         displayField: ["NAME"],
         searchFields: ["NAME"],
         suggestionTemplate: "${NAME}",
         enableSearchingAll: false,
         enableSuggestions: true,
         exactMatch: false,
         minCharacters: 3
        }
];

this.searchWithSuggestions = new Search({
        sources: searchSources,
        popupEnabled: false,
        autoSelect: false, 
        enableSourcesMenu: false,
        enableSuggestions: true,
        maxSuggestions: 5,
        allPlaceholder: "enter your search here",
        autoNavigate: false
}, "searchWithSuggestions");

this.searchWithSuggestions.startup();
},‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Search widget shows up in widget. But when i start typing and get past 3 characters (minCharacters), it fails with 

So something clearly is not right with the suggestions. I've checked the map service and it supports pagination. Something wrong with my code, something else I need to check ? 

0 Kudos
2 Replies
Arne_Gelfert
Occasional Contributor III

Been racking my brains here (bruisin' em). Am I missing the obvious?

I've come across two BUGS that don't sound exactly like have what's going on here by have given me reason to tweak my solution.

First one - BUG-000095810: The Search widget returns a "no results found" messa..  Search widget does not work against fields using coded value domains. Sure enough the Feature Layer I'm searching had domains although not the field that is my display and search field. So I replaced 

Second one - BUG-000121482: The Search widget in Web AppBuilder for ArcGIS fails.. . Search widget apparently doesn't work with SQL database views. I had recently set this up with a view to avoid the join someone else's had set up in the map project, which in turn prevented pagination. So I tried various values for maxSuggestions and finally replaced the view with a completely new table without domain and republished using Pro 2.5.

I have created a brand new app in WAB to rule out that I've contaminated any of the OTB files. I've tried to go through the actual API code for inits.js and Search.js. But it's impossible to decipher the minified code. My gut tells there is some communication breakdown between the widget and the map service. But I don't know how to further test. Any suggestions?

0 Kudos
Arne_Gelfert
Occasional Contributor III

Rebuilding from scratch a 3rd of 4th time, finally did the trick. Oh how I wish that error messages were a little more helpful when working with the JSAPI.