Hello everyone,
In a WebMap I am looking for a way to hide a field when it does not have values, and show it when it has values in a Popup window, when clicking in feature on the webmap.
Thanks
Please check the following blog Hide Field in Pop-up Using Arcade
I can't believe I missed that blog post! That's a really useful example, one that I will be using in a number of maps.
It can be kind of tricky to do this and have it formatted nicely, but here's a way to do it:
var x = $feature['attribute']
if(!IsEmpty(x)){
return `\nSome Attribute: ${x}`
}
Then in the popup configuration, put all the expressions on the same line. The \n in the returned string will separate multiple values.
To show what this might look like in practice, I'll use a static dict instead of the feature's attributes so that you can see the skipped values. My input:
var d = {
'first': 'the first value',
'second': null,
'third': null,
'fourth': 'and the fourth'
}
And the popup configuration:
And the resulting popup:
You'll have to do extra work if you want the output to look nice or have a tabular alignment, but this can at least give you a list of non-null / non-empty attributes in your feature that won't leave blank spaces.
EDIT: It occurred to me after posting that that there's no need for multiple expressions. If you build a dict from the attributes you want, you can return a single string with all the attributes in one go:
var attrs = {
'First': $feature['attribute1'],
'Second': $feature['attribute2'],
'Third': $feature['attribute3']
}
out_str = 'Attributes:'
for(var a in attrs){
if(!IsEmpty(attrs[a])){
out_str += `\n${a}: ${attrs[a]}`
}
}
return out_str
Here is a simple example that could work:
var FIRE = $feature.FIRE
var popuptext = ''
If(FIRE=='Yes'){
popuptext = 'There is a fire here.';
}
return popuptext
-----------------------------------
Brian Baldwin, Esri Inc., Lead Solution EngineerThank you for your samples.
Now how can I make the field clickable, because what I want to show/hide is a ProjectURL
Thanks
Well, that is a very different thing. If you want clickable links, you have to do it one expression per field, there's just no way to get the "<a href=...>" HTML tags into a dynamic list within a single expression. Configuring a popup to show "<a href={expression/expr0}>{expression/expr0</a>" works, where the expression returns a valid URL.
However, if the popup was "{expression/expr0}", where the expression returns all the <a href...></a> tags within it, that will not work, as the HTML tags will be read and displayed as text characters. With that in mind, you could try:
There's no way to get the newline character into the link, however, so you'll be once again stuck with either a really long horizontal string of text, or a tall list with empty rows.
Add to this the fact that your URLs may be long, and you may wish to display some other text. If you wish to do that, you'll need TWO expressions per field, one for the URL, one for the link text.
PS - Sorry for accepting and then unaccepting your post as a solution, I was meaning to click "reply". 😬
EDIT: You could probably get nicer URL labels with one expression per field using the method in the blog post @JayantaPoddar linked to.
Thanks Josh,
Your first sample worked for me.
I only have one field that has URL values in my Popup window. And I am not using the table HTML, just the default custom text display. Now it show as a text field, I need to find a way to make if clickable.
var relatedrecords = OrderBy(FeatureSetByRelationshipName($feature,"CIPProject"), "ProjectURL")
var cnt = Count(relatedrecords);
var relatedinfo = "";
if (cnt > 0) {
var info = First(relatedrecords);
relatedinfo = info.ProjectURL ;
}
return relatedinfo;
Hello again,
I was able to convert the field to a hyperlink field. I just selected the field, added hyperlink and copied {relationships/0/ProjectURL}" inside.
Thanks