Difficulty Removing Underscores from Field in PopupTemplate

312
4
Jump to solution
03-01-2024 06:19 PM
Med-Karim-Rouissi
New Contributor III

Hello ESRI Community,

I hope this message finds you well. I'm currently facing an issue with the JavaScript API for ArcGIS 4.24 while attempting to display the "Name_en" attribute in a PopupTemplate without underscores. Despite trying various approaches, the field's content is not being displayed as expected.

 

Here is a snippet of my current code:

 

let poptemp;

poptemp = new PopupTemplate({
    title: "{Name}",
    content: [{
        type: "fields",
        fieldInfos: [
            {
                fieldName: "Name_ar",
                label: "Name_ar"
            },
            {
                fieldName: "Name_en".replace(/_/g, ''),  
                label: "Name_en"
            },
            {
                fieldName: "Wiki_ar_link",
                label: "Wiki_ar_link"
            },
            {
                fieldName: "Wiki_en_link",
                label: "Wiki_en_link"
            }
        ]
    }]
});

 

 

I have attempted to utilize the replace method to remove underscores in the "Name_en" field, but it doesn't seem to work as intended. I've also explored the use of expressionInfos without success.

If anyone has encountered a similar issue or has suggestions on how to correctly format the "Name_en" field within a PopupTemplate, I would greatly appreciate your insights.

Thank you in advance for your assistance!

Best regards,

Karim

0 Kudos
1 Solution

Accepted Solutions
MatthewDriscoll
MVP Alum

You need to do this using arcade in the expressionInfos.  

View solution in original post

4 Replies
MatthewDriscoll
MVP Alum

You need to do this using arcade in the expressionInfos.  

MatthewDriscoll
MVP Alum

See this code pen for a working example.  It replaces "," with "  ZZZZ  '.

https://codepen.io/mbdriscoll/pen/gOyprmg

 

Med-Karim-Rouissi
New Contributor III

Hi, thank you very much for your help on the Esri forum! Your suggestion really worked and I was able to resolve my issue. I really appreciate your time and expertise.

Here is my code:

let poptemp;
	   
poptemp = new PopupTemplate({
    title: "{Name}",
    content: [{
        type: "fields",
        fieldInfos: [
            {
                fieldName: "Name_ar",
                label: "Name_ar"
            },
            {
                fieldName: "expression/Name_en",
                label: "Name_en",
            },
            {
                fieldName: "Wiki_ar_link",
                label: "Wiki_ar_link"
            },
            {
                fieldName: "Wiki_en_link",
                label: "Wiki_en_link"
            }
        ]
    }],
    expressionInfos:[
            {
                title: "Name_en",
                name: "Name_en",
                expression: "Replace($feature.Name_en, '_', '')", 
            }
            ]
});

Best,

Med-Karim Rouissi

0 Kudos
Med-Karim-Rouissi
New Contributor III

"One last question, the modules: "esri/popup/ExpressionInfo" and "esri/support/arcadeUtils", seem not to be necessary? They are not visible in your example, and in my code, their presence or absence doesn't make any difference. I simply have fewer errors in my console when I don't use them. The errors are non-blocking, and I am using the ArcGIS API for JavaScript 4.24 due to the requirements of my application."

0 Kudos