Problem with URLs not hyperlinking in AGOL Pop-Ups

2686
4
Jump to solution
01-22-2021 02:04 PM
AmyRoust
Occasional Contributor III

I have a dataset with a field that is either populated with a web address (https://....) or the text N/A. If there is a URL, I want to display it as a hyperlink in the pop-up so that the end user can just click to open it. I wrote up a conditional statement in Arcade and tried to plug it into HTML view in the pop-up custom configuration, but it only returns the HTML code in the pop-up, rather than recognizing the <a href> tag and adding the link.

Here is my Arcade code:

var webURL = $feature["Location_website"]
var linkYes = '<a href="{Location_website}" target="_blank"><b>{Location_website}</b></a>'
var linkNo = 'Website: <b>{Location_website}</b>'

when(webURL == 'N/A', linkNo, linkYes)

 And here is where I put the expression (I replace the highlighted text with {expression/expr0}

AmyRoust_1-1611352866006.png

And here is the pop-up (forgive my messy redaction work):

AmyRoust_2-1611352989274.png

 

Is there a better way to do this? I don't want to use the WYSIWYG editor to insert a hyperlink because I don't want N/A to be an active link that goes to nowhere.

 

 

 

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi @AmyRoust ,

 

I notice that you are trying to return HTML from the Arcade expression. This does not work in ArcGIS Online (it does in Pro). When you return HTML from an Arcade expression it will interpret it as plain text and not as HTML.

What you need to do is use a different approach. Have a look at this post: https://community.esri.com/t5/arcgis-online-documents/conditional-field-display-with-arcade-in-pop-u... Here you will see that you can conditionally display part of your content.

So, your HTML should include both cases (link available and link not available), but depending on the situation you will hide or show each part. This will multiple expressions, but it is not very complex to achieve this.

View solution in original post

0 Kudos
4 Replies
XanderBakker
Esri Esteemed Contributor

Hi @AmyRoust ,

 

I notice that you are trying to return HTML from the Arcade expression. This does not work in ArcGIS Online (it does in Pro). When you return HTML from an Arcade expression it will interpret it as plain text and not as HTML.

What you need to do is use a different approach. Have a look at this post: https://community.esri.com/t5/arcgis-online-documents/conditional-field-display-with-arcade-in-pop-u... Here you will see that you can conditionally display part of your content.

So, your HTML should include both cases (link available and link not available), but depending on the situation you will hide or show each part. This will multiple expressions, but it is not very complex to achieve this.

0 Kudos
AmyRoust
Occasional Contributor III

Thank you! This was a successful workaround for me. It's nice to be able to suppress empty fields.

I noticed that the automatic hyperlinking still happens in pop-ups if you use the option to display a list of fields or a single field in the pop-up, but not if you do a custom pop-up. In that case, you have to use the URL button to create a link, which is an all-or-nothing proposition for right now (either everything is hyperlinked or nothing is hyperlinked). Maybe we'll get more versatility with Arcade modifying HTML down the road.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @AmyRoust , 

I agree that it would be great to be able to return HTML from an Arcade expression in AGOL. You don't need a button to enable a hyperlink (this can be a normal anchor "<a href...>"). If you have any problems getting the result you want, just let me know and I will try and help.

0 Kudos
AmyRoust
Occasional Contributor III

Agreed - I can put in the HTML tags instead of using the button. Regardless of the method for hyperlinking, however, it's an all or nothing proposition. Either the hyperlinks exist for every data entry or for nothing. I can't have a "N/A" text display for the URL without it hyperlinking. That's OK -- hiding the entire row solves that issue.