Popuptemplate set field value dynamically JS API 4.X

69
0
10-28-2021 08:52 PM
PrashantKirpan
Occasional Contributor

Hi,

I want to set new field and value dynamically in popup. I'm watching popup's select feature property and set dynamic field in template and value to graphics attributes.

Popup is showing field name but value is empty.

Here is my sample code:

 

 

 fl= new FeatureLayer({
                url: serviceBaseUrl + "/FeatureServer/0",
                popupTemplate: {
                    title: "{name}",
                    outFields: ["*"],
                    lastEditInfoEnabled: false,                    
                    content: [
                        {
                            type: "fields",
                            fieldInfos: [
                                {
                                    fieldName: "defaultfield",
                                    label: 'DefaultField'
                                }
                            ]
                        }]
                }
            });

  view.popup.watch("selectedFeature", (graphic) => {
                if (graphic) { 
                    const graphicTemplate = graphic.getEffectivePopupTemplate();

                    let fieldInfo = new FieldInfo({
                        fieldName: 'dynamicfield',
                        label: 'Dynamic Field'
                    });

                    graphic.setAttribute('dynamicfield', 'Dynamic Value');
                    graphicTemplate.content[0].fieldInfos.push(fieldInfo); 
                }
            });

 

 

How to set dynamic values into popup? Any help would be appreciated.

-Prashant

 

0 Kudos
0 Replies