JSAPI 4.4 PopupTemplate Default Content

1265
2
Jump to solution
09-06-2017 02:13 PM
SamDrummond3
New Contributor

I'm having trouble setting a popup template for a feature layer.  Based on the documentation I expected to be able define a PopupTemplate object, define the fieldInfos property and leave the content property null resulting in the popup displaying the fieldInfos as a table as documented here:

However, when I do this, the popup appears blanks:

I have to manually set the content property as follows to get the populate:

var popupTemplate = new PopupTemplate(this._config.popupInfo);
popupTemplate.content = [{
   type:"fields",
   fieldInfos:popupTemplate.fieldInfos
}]

this._featureLayer.outFields = ["*"];
this._featureLayer.popupTemplate = popupTemplate;
return this._featureLayer;

Am I doing something wrong or is the documentation incorrect?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Sam,

   I think that the documentation could explain this a little better. You currently have to define the content as type fields if you are only providing the fieldInfos (lines 4-6).

      // autocasts as new PopupTemplate()
      var template = {
        title: "Marriage in NY, Zip Code: {ZIP}",
        content: [{
          type:"fields"
        }],
        fieldInfos: [{
          fieldName: "MARRIED_CY",
          format: {
            digitSeparator: true, // Use a comma separator for large numbers
            places: 0 // Sets the number of decimal places to 0 and rounds up
          }
        }, {
          fieldName: "NEVMARR_CY",
          format: {
            digitSeparator: true,
            places: 0
          }
        }, {
          fieldName: "DIVORCD_CY",
          format: {
            digitSeparator: true,
            places: 0
          }
        }]
      };

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Sam,

   I think that the documentation could explain this a little better. You currently have to define the content as type fields if you are only providing the fieldInfos (lines 4-6).

      // autocasts as new PopupTemplate()
      var template = {
        title: "Marriage in NY, Zip Code: {ZIP}",
        content: [{
          type:"fields"
        }],
        fieldInfos: [{
          fieldName: "MARRIED_CY",
          format: {
            digitSeparator: true, // Use a comma separator for large numbers
            places: 0 // Sets the number of decimal places to 0 and rounds up
          }
        }, {
          fieldName: "NEVMARR_CY",
          format: {
            digitSeparator: true,
            places: 0
          }
        }, {
          fieldName: "DIVORCD_CY",
          format: {
            digitSeparator: true,
            places: 0
          }
        }]
      };
SamDrummond3
New Contributor

Thanks rscheitlin‌, that was exactly the answer.  Given that across the platform, the default popup is a table view that displays all visible fields - it would probably make sense for the API to assume this by default.

0 Kudos