AnsweredAssumed Answered

Search Widget - Customize InfoTemplate

Question asked by cleotokos on Jan 22, 2016

I would like to customize the InfoTemplate that pops up when the search widget is used, but I'm having some unexpected results. Here is my code for the search source:

 

//Lots layer
sources.push({
            featureLayer: lyrLots,
            searchFields: ["PID", "LOT_NO", "OWNER"],
            exactMatch: false,
            outFields: ["*"],
     displayField: "LOT_NO",
            suggestionTemplate: "PID: ${PID}, Lot #: ${LOT_NO}, Owner: ${OWNER}",
            name: "Lots",
            placeholder: "Search Lots",
            maxResults: 6,
            maxSuggestions: 6,
            //Create an InfoTemplate and include fields
            infoTemplate: new InfoTemplate("Lots", "PID: ${PID}</br>Lot #: ${LOT_NO}</br>Owner: ${OWNER}</br>Title Link: ${TITLE_LINK:testLink}"),
            minCharacters: 0
         });

 

And the code to customize "Title Link" depending on whether a link is present or not:

 

    //The following determines whether a hyperlink is present in a field. If no hyperlink, the field will
    //show "Not available" in the infoWindow. If there is a hyperlink, the field will show "Click to open" as a hyperlink
    testLink = function (value, key, data) {
        var result = "";
        //If hyperlink field is null or contains a space, add "Not available" to the infoWindow
        if((value === " " && typeof value === "string")||(value === null && typeof value === "object") || (typeof value === "undefined")){
            result = "Not available";
            }
            
        //Add the hyperlink if present
        else {
            result = "<a href ='" + value + "' target='_blank'>Click to open</a>";
            }
        alert("Result: " + result);
        return result;
          };

 

If I open my map and do a search immediately, it seems "testLink" is not firing. I tried placing an alert window in testLink and it does not pop up so I know testLink is not even running. However, if I do an "Identify" (which also uses testLink to format links in its resulting infoWindow) and then do a search, "testLink" does run and format things correctly. Once an "identify" has been performed, testLink will run when subsequent searches are performed but I have no idea why this is. Does anyone have any ideas?

Outcomes