HTML Custom Attribute does not register as HTML code

420
5
12-11-2018 02:41 PM
Highlighted
Occasional Contributor II

I am working on creating a hyperlink by configuring the popup through Attribute Expressions. The purpose is to create a telephone call link for all of the Municipalities. I have all of the numbers for all of the police departments and want to insert them into some HTML text which will be populated by creating a virtual field in Attribute Expressions.

When I have the full HTML in the field, the hyperlink is created, but when I write out the code by using Attribute Expressions below the HTML text just shows up with no link.

I would prefer to keep using a list of attributes instead of a custom display as I think this looks more professional, and would like to populate the HTML code as apposed to changing the HTML every time so that people more involved with the call center activities can make changes to the phone numbers.

      var phone = $feature.Police_Num1

      '<a href="tel:91' + phone + '">' + phone + '</a>'

Has anyone else had this issue or know how to solve for it?

Reply
0 Kudos
5 Replies
Highlighted
Esri Contributor

Hi Walter,

An Arcade expression just returns a value (in this case, a string containing HTML). The software receiving that value (in this case, ArcGIS Online's Map Viewer) is then in control of what happens with that value. The string value returned by the Arcade expression is getting "escaped" by the Map Viewer, to ensure that the value displayed in the popup is the same as the original string value. AFAIK, there's no way to tell Map Viewer that it should interpret the string returned by the Arcade expression as HTML (and that might present a security risk, anyway).

 

If you want to keep the look/feel of the default “list of attributes” display and still get the hyperlink, you can create a Custom Attribute Display that mimics the default “list of attributes” display, then tweak the custom display in the HTML editor, so it uses the string returned from the Arcade expression as the URL for an <a> tag. For example, check the Custom Attribute Display editor's HTML view in this sample:

https://www.arcgis.com/home/webmap/viewer.html?webmap=3a8a97d7d9c742e2985dbd0075ebaaf7&extent=-79.29... 

(You'll need to Sign In and Modify Map to be able to access the layer's Configure Popup option.)

Hope this helps a bit!

Jason

Highlighted
New Contributor III

Very Helpful, a light bulb came on after seeing the example.  Thank you.

Reply
0 Kudos
Highlighted
New Contributor III

I realize this thread is a bit old, but I was just checking to see if this feature is still not part of Arcade. I tried it on my web map but the html inside the arcade expression was just returned as text containing html code. =[

Reply
0 Kudos
Highlighted
New Contributor III

How would I create a popup with a photo that is attached in the popup and a .pdf that is attached for view? 

Thank you!

Reply
0 Kudos
Highlighted
New Contributor III

This is how i set up the expression to return the pdf link, if the feature had a project number (which was the name of the pdf):

var projNum = IIf(IsEmpty($feature.ProjectNumber), "", $feature.ProjectNumber);
if (projNum == "Not Applicable"){
return "";
}
else {
return "https://prodmaps.ne.gov/NDOTrow/" +
$feature.ProjectNumber + ".pdf";
}

then just insert the expression into the html popup windo configuration:

Reply
0 Kudos