Is there a way to condition show fields in the content of a PopupTemplate? For example, if field 1 = "A", can I display field 2 and if field 1 = "B" can I display field 3?
I'd say not without doing some work on your own. I think you'd have to utilize a custom function to format the infoWindow's contents and use JS code to evaluate whether or not to show a given field. Something kind of like this:
template = new InfoTemplate(); template.setContent(SetPopupInfo); function SetPopupInfo(graphic) { //Function to compile the information to present in a feature identify window var fullAttr = graphic.attributes; var content; content = '<table width=\"100%\"><tr><td style=\"font-weight:bold;padding-left:3px;padding-right:3px\">Road Name:</td><td style=\"padding-left:3px;padding-right:3px\">' + fullAttr.rdName + '</td></tr>'; if (fullAttr.status == 'CLOSED') { content = content + '<tr><td style=\"font-weight:bold;padding-left:3px;padding-right:3px\">Status:</td><td style=\"color:red;font-weight:bold;padding-left:3px;padding-right:3px\">' + fullAttr.status + '</td></tr>'; } else { content = content + '<tr><td style=\"font-weight:bold;padding-left:3px;padding-right:3px\">Status:</td><td style=\"color:green;font-weight:bold;padding-left:3px;padding-right:3px\">' + fullAttr.status + '</td></tr>'; } content = content + '<tr><td style=\"font-weight:bold;padding-left:3px;padding-right:3px;vertical-align:top\">Start of Closure:</td><td style=\"padding-left:3px;padding-right:3px;vertical-align:top\">' + fullAttr.cl_Start + '</td></tr>'; content = content + '<tr><td style=\"font-weight:bold;padding-left:3px;padding-right:3px;vertical-align:top\">End of Closure:</td><td style=\"padding-left:3px;padding-right:3px;vertical-align:top\">' + fullAttr.cl_End + '</td></tr>'; if (fullAttr.status == 'CLOSED') { content = content + '<tr><td style=\"font-weight:bold;padding-left:3px;padding-right:3px;vertical-align:top\">Closure Date:</td><td style=\"3padding-left:3px;padding-right:3px;vertical-align:top">' + formatDate(adjClosureDate) + ' @ ' + adjClosureTime + '</td></tr>'; } else { content = content + '<tr><td style=\"font-weight:bold;padding-left:3px;padding-right:3px;vertical-align:top\">Closure Date:</td><td style=\"3padding-left:3px;padding-right:3px;vertical-align:top">' + formatDate(adjClosureDate) + ' @ ' + adjClosureTime + '</td></tr>'; content = content + '<tr><td style=\"font-weight:bold;padding-left:3px;padding-right:3px;vertical-align:top\">Date Re-opened:</td><td style=\"3padding-left:3px;padding-right:3px;vertical-align:top">' + formatDate(adjOpenDate) + ' @ ' + adjOpenTime + '</td></tr>'; } content = content + '<tr><td style=\"font-weight:bold;padding-left:3px;padding-right:3px\">Reason:</td><td tyle=\"padding-left:3px;padding-right:3px\">' + fullAttr.reason + '</td></tr></table>'; return content; }
As you can see, the value of the attribute field STATUS dictates what and how something is shown in the infoWindow.
This is what the two options would look like in the app:
Thanks for your help, but unfortunately, this approach is not working in 4.0 with a PopupTemplate.
// CODE
var wrpProjectsPopupTemplate = new PopupTemplate({
title: "{MapLayer}",
content: setPopupTemplateContent()
});
function setPopupTemplateContent(graphic) {
try {
var attr = graphic.attributes; -- getting error the graphic is undefined
return attr;
}
catch (err)
{
return err.message;
}
}
I may see if I can either get the graphic on a map click of the view or find an alternative the the PopupTemplate.
Thanks
Chuck,
Setting the popups content by function is not available yet in 4.0.
Hi Robert,
Thanks for providing that informaiton. Is there any link where people can see what is being developed for the next release of 4.0 and/or what the schedule is?
Thanks,
Chuck
Just found this: FAQs | ArcGIS API for JavaScript 4.0