<?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: Clear Widget and Map on Close in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1523315#M14357</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I believe custom widget is NOT unmounted when it is closed in Exb, just hidden, this is a problem in that the things you want to do in componentWillMount (e.g. read selected feature on a map when the widget is reopened) will not run because the widget is not unmounted after that very first time being loaded. Is there any way to force unmount a widget when its state becomes 'CLOSED' (i.e. this.props.state === 'CLOSED'), I mean there ought be ways to force remove widget from DOM, so the will mount hook can run after close. I tried a number of ways, a browser refresh seems to be only reliable way to reset the state fully. Full disclosure, I've tried the following ways:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ReactDOM.unmountComponentAtNode/componentDidUpdate&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;WidgetManager.destroyWidgetByUri&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate any suggestion that can reliably unmount the widget when it is close.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 18 Aug 2024 15:27:16 GMT</pubDate>
    <dc:creator>tzhaigeo</dc:creator>
    <dc:date>2024-08-18T15:27:16Z</dc:date>
    <item>
      <title>Clear Widget and Map on Close</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1326527#M8229</link>
      <description>&lt;P&gt;I have created a custom widget with input boxes which creates a graphic on a map. I have a "Trash Can" icon button on the widget which the user can hit to clear the map and all input info in the widget. This all works fine.&lt;/P&gt;&lt;P&gt;I would like to use the widget from the (out of the box) top widget ribbon, which allows for a nice icon button that opens and closes the widget. When the widget is open there is then also a "Close X" at the right top hand corner of the widget.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;My problem is that if the user closes the widget using the "X" or the ribbon icon button, the widget dialog box will close but it won't clear and the map won't clear (if the user hasn't hit the "Trash Can" button first). I would like closing the widget to function just like hitting the "Trash Can" button, but I can't see how to capture the closing event.&lt;/P&gt;&lt;P&gt;I have tried using&amp;nbsp;&lt;SPAN&gt;componentWillUnmount and componentDidUpdate but I have not been successful.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I have already seen this post on the widget close event but it is not helping me out -- maybe someone can clarify or elaborate?&amp;nbsp;&lt;BR /&gt;&lt;A href="https://community.esri.com/t5/arcgis-experience-builder-questions/widget-close-event/m-p/1040177/thread-id/1658" target="_blank"&gt;https://community.esri.com/t5/arcgis-experience-builder-questions/widget-close-event/m-p/1040177/thread-id/1658&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 18:34:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1326527#M8229</guid>
      <dc:creator>EMiller_2</dc:creator>
      <dc:date>2023-09-07T18:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: Clear Widget and Map on Close</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1326537#M8230</link>
      <description>&lt;P&gt;Are you using class based or function based React components? I assume that you are using class based as componentWillUnmount and componetDidUpdate have been replaced by useEffect in function based React. Regardless, I believe the reason these methods did not work for you is that in Experience Builder widgets never actually unmount. They just hide when they are dismissed. (I am not 100% sure that is factual.) I did something like this in a class based component to watch if it was closed in a widget controller.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;componentDidUpdate (prevProps) {
  if (prevProps.state === 'CLOSED') {
     return this.functionToRestartYourWidget()
  }
  if (this.props.state === 'CLOSED') {
    this.fuctionToCloseYourWidget()
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 19:21:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1326537#M8230</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-09-07T19:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: Clear Widget and Map on Close</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1326557#M8232</link>
      <description>&lt;P&gt;Thanks Jeffrey! You put me on the right track -- I can't believe how simple the solution was. (Yes, it is a class based widget). All I did was this and it is working perfectly now. Hopefully I'm not overlooking something but this did the trick:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;componentDidUpdate () {
    if (this.props.state === 'CLOSED') {
      console.log("I'm closed!")
      this.myWidget.clear();
      this.mydrawLayer.removeAll();
      this.setState({
        inputText: "",    
      });
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 15:39:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1326557#M8232</guid>
      <dc:creator>EMiller_2</dc:creator>
      <dc:date>2023-09-08T15:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Clear Widget and Map on Close</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1341786#M8922</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/470079"&gt;@EMiller_2&lt;/a&gt;&amp;nbsp;Where does insert this code? File in Server or Client.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 03:27:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1341786#M8922</guid>
      <dc:creator>SupakornAngaumnuaysiri1</dc:creator>
      <dc:date>2023-10-26T03:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Clear Widget and Map on Close</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1341886#M8934</link>
      <description>&lt;P&gt;This code would go within the widget.tsx of a class based widget.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 12:30:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1341886#M8934</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-10-26T12:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: Clear Widget and Map on Close</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1342474#M8991</link>
      <description>&lt;P&gt;Thanks for your reply.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 03:09:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1342474#M8991</guid>
      <dc:creator>SupakornAngaumnuaysiri1</dc:creator>
      <dc:date>2023-10-27T03:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: Clear Widget and Map on Close</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1523314#M14356</link>
      <description>&lt;P&gt;I believe custom widget is NOT unmounted when it is closed in Exb, just hidden, this is a problem in that the things you want to do in componentWillMount (e.g. read selected feature on a map when the widget is reopened) will not run because the widget is not unmounted after that very first time being loaded. Is there any way to force unmount a widget when it is state is 'CLOSED', please advise.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2024 15:14:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1523314#M14356</guid>
      <dc:creator>tzhaigeo</dc:creator>
      <dc:date>2024-08-18T15:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: Clear Widget and Map on Close</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1523315#M14357</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I believe custom widget is NOT unmounted when it is closed in Exb, just hidden, this is a problem in that the things you want to do in componentWillMount (e.g. read selected feature on a map when the widget is reopened) will not run because the widget is not unmounted after that very first time being loaded. Is there any way to force unmount a widget when its state becomes 'CLOSED' (i.e. this.props.state === 'CLOSED'), I mean there ought be ways to force remove widget from DOM, so the will mount hook can run after close. I tried a number of ways, a browser refresh seems to be only reliable way to reset the state fully. Full disclosure, I've tried the following ways:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ReactDOM.unmountComponentAtNode/componentDidUpdate&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;WidgetManager.destroyWidgetByUri&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate any suggestion that can reliably unmount the widget when it is close.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2024 15:27:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/clear-widget-and-map-on-close/m-p/1523315#M14357</guid>
      <dc:creator>tzhaigeo</dc:creator>
      <dc:date>2024-08-18T15:27:16Z</dc:date>
    </item>
  </channel>
</rss>

