AnsweredAssumed Answered

Popup template - conditional title formatting JS 4.14

Question asked by psba_ldudina on Dec 23, 2019
Latest reply on Jan 1, 2020 by psba_ldudina

I'd like to change color of the popup title depending on the value in the field. There are four possible values.

 

 

Here is my code related to this popup:

 

// setting up popup template

let template = {
title: title(),
content: [
{
type : "fields",
fieldInfos: [
{
fieldName: "CurrentWarning",
label:"Current Warning",
},
{
fieldName: "Location",
label:"Location",
},
{
fieldName: "MediaMessage",
label:"Media Message",
},
{
fieldName: "ResponseDate",
label:"Response Date",
},
{
fieldName: "VehiclesOnScene",
label:"Vehicles on Scene",
},
{
fieldName: "VehiclesOnRoute",
label:"Vehicles on Route",
},
{
fieldName: "LastUpdate",
label:"Last Update",
}
]
}]
};

Then feature layer gets the popupTemplate setup:

var featureLayer = new FeatureLayer({
url:
"http://services1.arcgis.com/....../arcgis/rest/services/......./0",
popupTemplate: template
});
map.add(featureLayer);

And last part, definition for title() function:

function title() {
if ( {CurrentWarning} == "Emergency Warning"){
return "<font color='#FF0000'>{CurrentWarning} - {Location}"
} else if ({CurrentWarning} == "Advice"){
return "<font color='#FFFF00'>{CurrentWarning} - {Location}"
} else if ({CurrentWarning} == "Watch and Act"){
return "<font color='#ff6600'>{CurrentWarning} - {Location}"
} else {
console.log({CurrentWarning} )
return "<font color= '#008000'>{CurrentWarning} - {Location}"
 }
}

 

What happens is that {CurrentWarning} in the title function is not defined

 

I tried passing the value through the function:

 

......

title: title("{CurrentWarning}"),

.......

function title(warning) {

.......

}

 

That did not work.

 

And I also tried to use quotes around CurrentWarning, same outcome.

 

How do I get the different color for the title depending on the value of this field?

 

Thanks!

Outcomes