<?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 Re: Custom popup actions misfires on second popup open in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-popup-actions-misfires-on-second-popup-open/m-p/1152991#M76624</link>
    <description>&lt;P&gt;If you click somewhere and there is not a 'graphic' object the code stops because you are trying to 'getEffectivePopupTemplate()' from a 'null' object.&amp;nbsp; I put in the check for null and it seems to work.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.when(() =&amp;gt; {
    view.popup.watch("selectedFeature", (graphic) =&amp;gt; {
        if (graphic != null) {
            const graphicTemplate = graphic.getEffectivePopupTemplate();
            if (view.popup.viewModel.selectedFeature.attributes.restricted == "True")
            {
                graphicTemplate.actions.items[0].visible = false;
                console.log('hidden');
            } else {
                graphicTemplate.actions.items[0].visible = true;
                console.log('showing');
            }
        }
    })
});&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 11 Mar 2022 17:07:18 GMT</pubDate>
    <dc:creator>JeffreyWilkerson</dc:creator>
    <dc:date>2022-03-11T17:07:18Z</dc:date>
    <item>
      <title>Custom popup actions misfires on second popup open</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-popup-actions-misfires-on-second-popup-open/m-p/1152515#M76618</link>
      <description>&lt;P&gt;I have followed the example code here to get custom popup actions to show depending on a feature's attribute: &lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/popup-custom-action/" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/sample-code/popup-custom-action/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;My code works well the first time the first time a feature is clicked after load, but upon closing that popup or switching to another point, the popup box will jump to the top left corner and not show any information.&lt;/P&gt;&lt;P&gt;In the browser console, the error upon the second time popup opening is "Uncaught TypeError: Cannot read properties of null (reading 'getEffectivePopupTemplate')".&lt;/P&gt;&lt;P&gt;I can't figure out why it fires correctly the first time but not the second.&lt;/P&gt;&lt;P&gt;If anyone could point me in the right direction I'd be very grateful, thanks!&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;view&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;when&lt;/SPAN&gt;&lt;SPAN&gt;(() &lt;/SPAN&gt;&lt;SPAN&gt;=&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt; {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;view&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;popup&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;watch&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"selectedFeature"&lt;/SPAN&gt;&lt;SPAN&gt;, (&lt;/SPAN&gt;&lt;SPAN&gt;graphic&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;SPAN&gt;=&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt; {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;const&lt;/SPAN&gt; &lt;SPAN&gt;graphicTemplate&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;graphic&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;getEffectivePopupTemplate&lt;/SPAN&gt;&lt;SPAN&gt;();&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;view&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;popup&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;viewModel&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;selectedFeature&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;attributes&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;restricted&lt;/SPAN&gt;&lt;SPAN&gt; == &lt;/SPAN&gt;&lt;SPAN&gt;"True"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;graphicTemplate&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;actions&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;items&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;].&lt;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&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;console&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;log&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'showing'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; })&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; });&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 10 Mar 2022 12:19:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-popup-actions-misfires-on-second-popup-open/m-p/1152515#M76618</guid>
      <dc:creator>JasmineNoble-Shelley</dc:creator>
      <dc:date>2022-03-10T12:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Custom popup actions misfires on second popup open</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-popup-actions-misfires-on-second-popup-open/m-p/1152991#M76624</link>
      <description>&lt;P&gt;If you click somewhere and there is not a 'graphic' object the code stops because you are trying to 'getEffectivePopupTemplate()' from a 'null' object.&amp;nbsp; I put in the check for null and it seems to work.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.when(() =&amp;gt; {
    view.popup.watch("selectedFeature", (graphic) =&amp;gt; {
        if (graphic != null) {
            const graphicTemplate = graphic.getEffectivePopupTemplate();
            if (view.popup.viewModel.selectedFeature.attributes.restricted == "True")
            {
                graphicTemplate.actions.items[0].visible = false;
                console.log('hidden');
            } else {
                graphicTemplate.actions.items[0].visible = true;
                console.log('showing');
            }
        }
    })
});&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 11 Mar 2022 17:07:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-popup-actions-misfires-on-second-popup-open/m-p/1152991#M76624</guid>
      <dc:creator>JeffreyWilkerson</dc:creator>
      <dc:date>2022-03-11T17:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Custom popup actions misfires on second popup open</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-popup-actions-misfires-on-second-popup-open/m-p/1153299#M76635</link>
      <description>&lt;P&gt;Thank you Jeffery! This works perfectly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 11:17:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-popup-actions-misfires-on-second-popup-open/m-p/1153299#M76635</guid>
      <dc:creator>JasmineNoble-Shelley</dc:creator>
      <dc:date>2022-03-14T11:17:06Z</dc:date>
    </item>
  </channel>
</rss>

