<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic PopupTemplate FieldInfo with HTML onclick no longer available in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popuptemplate-fieldinfo-with-html-onclick-no/m-p/1266303#M80506</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I was originally on 4.11 and&amp;nbsp; updated to 4.26 and noticed that the when displaying field attribute values it no longer renders HTML as expected.&amp;nbsp; I did some Googling and saw that this is expected due to the added sanitize feature.&amp;nbsp; I was able to fix up some of my popup HTML content using CustomContent, but I'm stuck on the FieldInfo portion for FieldsContent.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="YimYean_1-1678406825562.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/64874i515E51ADCF76C386/image-size/large?v=v2&amp;amp;px=999" role="button" title="YimYean_1-1678406825562.png" alt="YimYean_1-1678406825562.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Below is my sample code.&amp;nbsp; I was able to use CustomContent to display the HTML as expected, but not getting same outcome with Fields for &lt;STRONG&gt;onclick&lt;/STRONG&gt; in&amp;nbsp;&lt;STRONG&gt;populationChange&lt;/STRONG&gt; function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&amp;gt;
    &amp;lt;meta
      name="viewport"
      content="initial-scale=1, maximum-scale=1,user-scalable=no"
    /&amp;gt;
    &amp;lt;link
      rel="stylesheet"
      href="https://js.arcgis.com/4.26/esri/themes/light/main.css"
    /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.26/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script&amp;gt;
      function alertTest(e) {
        e.preventDefault();
        alert("test");
      }
    &amp;lt;/script&amp;gt;
    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    &amp;lt;/style&amp;gt;

    &amp;lt;script&amp;gt;
      let populationChange;
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/Layer",
        "esri/popup/content/FieldsContent",
        "esri/popup/content/CustomContent",
        "esri/popup/FieldInfo"
      ], (Map, MapView, Layer, FieldsContent, CustomContent, FieldInfo) =&amp;gt; {
        const map = new Map({
          basemap: "dark-gray-vector"
        });

        // Create the MapView
        const view = new MapView({
          container: "viewDiv",
          map: map,
          zoom: 6,
          center: [-87, 34]
        });

        Layer.fromPortalItem({
          portalItem: {
            // autocasts as new PortalItem()
            id: "e8f85b4982a24210b9c8aa20ba4e1bf7"
          }
        }).then((layer) =&amp;gt; {
          // add the layer to the map
          map.add(layer);

          const popupTemplate = {
            // autocasts as new PopupTemplate()
            title: "Population in {NAME}",
            outFields: ["*"],
            content: populationChange,            
          };

          layer.popupTemplate = popupTemplate;

          function populationChange(feature) {
            let fieldInfo1 = new FieldInfo({
              fieldName: "POP2013",
              label: "Test HTML",
              visible: true
            });
            
            const attributes = feature.graphic.attributes;
                        
            const fieldDiv = document.createElement("div");
            const fieldA = document.createElement("a");                        
            fieldA.href = "https://www.google.com";
            fieldA.target = "_blank";
            fieldA.innerHTML = "Click me!";
            fieldA.onclick = "alertTest(event)";            
            fieldDiv.appendChild(fieldA);
            
            // Tried doing something like this for the field but still no luck
            //attributes["POP2013"] = fieldDiv.innerHTML;
            
            const customDiv = document.createElement("div");
            
            customDiv.innerHTML = "&amp;lt;a target='_blank' href='https://www.google.com' style='color:blue' onclick='alertTest(event)'&amp;gt;Click Me!&amp;lt;/a&amp;gt;";
            
            // I also tried just assigning customDiv object but that just renders text [object HTMLDivElement]
            attributes["POP2013"] = customDiv.innerHTML;
            
            let fieldsElement = new FieldsContent({
              fieldInfos: [fieldInfo1]
            });
           
            
            let customContent = new CustomContent({ creator: customDiv });
            
            return [fieldsElement, customContent];
          }
        });
      });
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Mar 2023 00:14:10 GMT</pubDate>
    <dc:creator>YimYean</dc:creator>
    <dc:date>2023-03-10T00:14:10Z</dc:date>
    <item>
      <title>PopupTemplate FieldInfo with HTML onclick no longer available</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popuptemplate-fieldinfo-with-html-onclick-no/m-p/1266303#M80506</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I was originally on 4.11 and&amp;nbsp; updated to 4.26 and noticed that the when displaying field attribute values it no longer renders HTML as expected.&amp;nbsp; I did some Googling and saw that this is expected due to the added sanitize feature.&amp;nbsp; I was able to fix up some of my popup HTML content using CustomContent, but I'm stuck on the FieldInfo portion for FieldsContent.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="YimYean_1-1678406825562.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/64874i515E51ADCF76C386/image-size/large?v=v2&amp;amp;px=999" role="button" title="YimYean_1-1678406825562.png" alt="YimYean_1-1678406825562.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Below is my sample code.&amp;nbsp; I was able to use CustomContent to display the HTML as expected, but not getting same outcome with Fields for &lt;STRONG&gt;onclick&lt;/STRONG&gt; in&amp;nbsp;&lt;STRONG&gt;populationChange&lt;/STRONG&gt; function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&amp;gt;
    &amp;lt;meta
      name="viewport"
      content="initial-scale=1, maximum-scale=1,user-scalable=no"
    /&amp;gt;
    &amp;lt;link
      rel="stylesheet"
      href="https://js.arcgis.com/4.26/esri/themes/light/main.css"
    /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.26/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script&amp;gt;
      function alertTest(e) {
        e.preventDefault();
        alert("test");
      }
    &amp;lt;/script&amp;gt;
    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    &amp;lt;/style&amp;gt;

    &amp;lt;script&amp;gt;
      let populationChange;
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/Layer",
        "esri/popup/content/FieldsContent",
        "esri/popup/content/CustomContent",
        "esri/popup/FieldInfo"
      ], (Map, MapView, Layer, FieldsContent, CustomContent, FieldInfo) =&amp;gt; {
        const map = new Map({
          basemap: "dark-gray-vector"
        });

        // Create the MapView
        const view = new MapView({
          container: "viewDiv",
          map: map,
          zoom: 6,
          center: [-87, 34]
        });

        Layer.fromPortalItem({
          portalItem: {
            // autocasts as new PortalItem()
            id: "e8f85b4982a24210b9c8aa20ba4e1bf7"
          }
        }).then((layer) =&amp;gt; {
          // add the layer to the map
          map.add(layer);

          const popupTemplate = {
            // autocasts as new PopupTemplate()
            title: "Population in {NAME}",
            outFields: ["*"],
            content: populationChange,            
          };

          layer.popupTemplate = popupTemplate;

          function populationChange(feature) {
            let fieldInfo1 = new FieldInfo({
              fieldName: "POP2013",
              label: "Test HTML",
              visible: true
            });
            
            const attributes = feature.graphic.attributes;
                        
            const fieldDiv = document.createElement("div");
            const fieldA = document.createElement("a");                        
            fieldA.href = "https://www.google.com";
            fieldA.target = "_blank";
            fieldA.innerHTML = "Click me!";
            fieldA.onclick = "alertTest(event)";            
            fieldDiv.appendChild(fieldA);
            
            // Tried doing something like this for the field but still no luck
            //attributes["POP2013"] = fieldDiv.innerHTML;
            
            const customDiv = document.createElement("div");
            
            customDiv.innerHTML = "&amp;lt;a target='_blank' href='https://www.google.com' style='color:blue' onclick='alertTest(event)'&amp;gt;Click Me!&amp;lt;/a&amp;gt;";
            
            // I also tried just assigning customDiv object but that just renders text [object HTMLDivElement]
            attributes["POP2013"] = customDiv.innerHTML;
            
            let fieldsElement = new FieldsContent({
              fieldInfos: [fieldInfo1]
            });
           
            
            let customContent = new CustomContent({ creator: customDiv });
            
            return [fieldsElement, customContent];
          }
        });
      });
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 00:14:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popuptemplate-fieldinfo-with-html-onclick-no/m-p/1266303#M80506</guid>
      <dc:creator>YimYean</dc:creator>
      <dc:date>2023-03-10T00:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: PopupTemplate FieldInfo with HTML onclick no longer available</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popuptemplate-fieldinfo-with-html-onclick-no/m-p/1266521#M80510</link>
      <description>&lt;P&gt;Have you seen &lt;A href="https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-pop-up-onclick-is-not-rendering/m-p/1252966" target="_self"&gt;this thread&lt;/A&gt;?&amp;nbsp; You'll find various proposed solutions to this kind of problem there.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 17:03:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popuptemplate-fieldinfo-with-html-onclick-no/m-p/1266521#M80510</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2023-03-10T17:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: PopupTemplate FieldInfo with HTML onclick no longer available</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popuptemplate-fieldinfo-with-html-onclick-no/m-p/1266536#M80512</link>
      <description>&lt;P&gt;Thank you so much.&amp;nbsp; That was the solution I needed.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 17:16:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popuptemplate-fieldinfo-with-html-onclick-no/m-p/1266536#M80512</guid>
      <dc:creator>YimYean</dc:creator>
      <dc:date>2023-03-10T17:16:31Z</dc:date>
    </item>
  </channel>
</rss>

