I am attempting to use Arcade to configure pop-ups for a web map and web app.
I want the popup to display certain fields if they are not empty, but not display anything for the fields when they are empty. Using Text elements in the popup has the drawback of including whitespace for fields that are blank - so if several fields displayed in order are all empty, a large block of the popup is white space.
I have an Arcade expression to check whether fields are empty before appending them to the "return" text, but when I use this expression any carriage returns within the text body of an individual field are removed - so if a field has two or three paragraphs, it is all displayed as a single lump of text.
I have tried replacing any hidden newline characters in the text field with the Arcade TextFormatting.NewLine, but this did not help.
Any suggestions would be much appreciated!
You can usually add HTML tags to text and the popup will handle them, try subbing in <br />s instead of standard newlines.
I use the following code to aggregate 6 fields into one for our Title Deeds map. I never liked seeing fields; Ref_1, Ref_2, etc etc you get the picture, that the data custodians created.
This may give you an alternative way to manage the data within the pop-up. (just an idea)
First off, this is what my pop-up looks like when a single or multiple values sit in the attribute fields, then when one or none;
and this is what the code looks like;
what if you set aNL = '\n'
var aNL = '\n'
var popupString = ''
popupString += 'test' + aNL
popupString += 'test2' + aNL
popupString += 'test3' + aNL
popupString += 'LastString'
return popupString
R_
Here is another way to include new lines: template literals.
Edit: After rereading the post, I don't think template literals will help with pushing additional text on a new line.
Hi everyone, thank you all for chiming in, and sorry for the delay.
@JonathanMcD and @RhettZufelt - I appreciate the suggestions. If I'm not mistaken, this is the inverse of what I'm looking for in that it starts with individual strings in separate fields, then brings them together into a text body with the delineated paragraphs. This is something I have considered and successfully tested, and it may end up being the only workable solution, but I am hoping to find a way to include carriage returns from a multiline text field in the text as presented by an Arcade Expression because the layer currently contains the text in a single field - I'd like to skip reworking the schema to parse these fields apart if possible.
@DavidSolari I gave this a try as suggested but no joy. I am beginning to wonder if there's an issue with how I'm looking for newlines in the text to begin with - I am an amateur when it comes to using regex to scan text and also still learning my way around Arcade.
@KenBuja Adding an example of the pop-up and Arcade script below. Note that for the script I have tried a few different variations of the carriage return text to search for, and also tried using "TextFormatting.NewLine" instead of "<br />" with no change.
// Arcade expression to test newline/carriage return formatting for a single multiline text field displayed in pop-up
var raw_IntroField = $feature.Introduction;
var regexPattern = "(\r|\n|\t)";
// return {text : Find(raw_IntroField, regexPattern)}
var formatted_IntroField = Replace(raw_IntroField, regexPattern, "<br />");
return {
type : 'text',
text : formatted_IntroField
}
Text displayed from a text element vs Arcade expression
What is the actual text in the $feature.Introduction?