Add Text to Search Results

2783
4
03-23-2016 07:05 AM
JessicaGormont
New Contributor II

Is there a way to add text to the search results pop up window? We want to be able to tell our users to click on the map for more information.

Note: I am not a programmer. Please be as basic as possible in your explanation.

Tags (1)
0 Kudos
4 Replies
AdrianWelsh
MVP Notable Contributor

Hi Jessica,

I guess I'm not fully sure of what you are wanting to accomplish. Do you mean the regular pop-up that occurs in ArcGIS Online? If so, you can 'configure pop-ups' to add what you need to add:

Configure pop-ups—ArcGIS Online Help | ArcGIS

0 Kudos
JessicaGormont
New Contributor II

Not the information pop up that occurs when you click on something; I'm trying to edit the pop up that you get when you use the search widget. This does not draw from the ArcGIS Online pop up configurations.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Jessica,

Here is how to add some text to each and every search result popup:

edit the [install dir]\server\apps\[app#]\widgets\Search\Widget.js Line 31 is the change.

_onSearchResults: function(evt) {
        var sources = this.searchDijit.get('sources');
        var activeSourceIndex = this.searchDijit.get('activeSourceIndex');
        var value = this.searchDijit.get('value');
        var htmlContent = "";
        var results = evt.results;
        var _activeSourceNumber = null;
        if (results && evt.numResults > 0) {
          console.info(results);
          html.removeClass(this.searchDijit.containerNode, 'showSuggestions');

          this.searchResults = results;
          htmlContent += '<div class="show-all-results jimu-ellipsis" title="' +
            this.nls.showAll + '">' +
            this.nls.showAllResults + '<strong >' + value + '</strong></div>';
          htmlContent += '<div class="searchMenu" role="menu">';
          for (var i in results) {
            if (results && results.length) {
              var name = sources[parseInt(i, 10)].name;
              if (sources.length > 1 && activeSourceIndex === 'all') {
                htmlContent += '<div title="' + name + '" class="menuHeader">' + name + '</div>';
              }
              htmlContent += "<ul>";
              var partialMatch = value;
              var r = new RegExp("(" + partialMatch + ")", "gi");
              var maxResults = sources.maxResults;

              for (var j = 0, len = results.length; j < len && j < maxResults; j++) {
                var text = esriLang.isDefined(results.name) ?
                  results.name : this.nls.untitled;
                results.name += "<br> This is my added text";

                htmlContent += '<li title="' + text + '" data-index="' + j +
                  '" data-source-index="' + i + '" role="menuitem" tabindex="0">' +
                  text.toString().replace(r, "<strong >$1</strong>") + '</li>';
              }
              htmlContent += '</url>';

              if (evt.numResults === 1) {
                _activeSourceNumber = i;
              }
            }
          }
          htmlContent += "</div>";
          this.searchResultsNode.innerHTML = htmlContent;

          this._showResultMenu();

          this._resetSelectorPosition('.searchMenu');
        } else {
          this._onClearSearch();
        }
      },
RobertScheitlin__GISP
MVP Esteemed Contributor

Jessica,

  Don't forget to mark this thread as answered by clicking on the "correct answer" link on the thread that answered your question.

0 Kudos