widget question: destroy event?

4716
2
Jump to solution
05-14-2015 01:08 PM
by Anonymous User
Not applicable

I want to remove the click handler in my Pictometry widget if the user closes the widget. Regardless whether they've already clicked on the map. (I already have the covered, after the window.open(url), the next line is handlerPictometry.remove() )  Because currently the map.on 'click' handler stays active until the map is clicked on. I want to remove it when the widget closes.

Oddly enough Dojo docs do not talk about hooking to a widget closing.

I referred to Understanding _WidgetBase - Dojo Toolkit Tutorial  and Writing Your Own Widget — The Dojo Toolkit - Reference Guide  etc

But I found this useful thread, the aspect.after post: javascript - Do dojo widgets emit an event when destroyed or can you force one to? - Stack Overflow 

So I figured I should be able to just do this code below, right?  It doesn't fire. Neither does using this.on or this.own(on

or other Dojo-recommended patterns.  And I made sure I required all the right modules etc. No console errors. It just doesn't fire. In terms of where it'd be, it's just inside the "clazz" in my Pictometry widget I posted on here.  I'll continue working on this. I want to get this working before posting my widget update which has some of the other new stuff, too.

I'm new to writing widgets and this is my first so it could likely be something simple.

  startup: function () {

            this.inherited(arguments);

         aspect.after(this, 'destroy', function () {
   alert('destroyed'); //or..handlerPictometry.remove();

}, true);

        }

1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor II

For Web AppBuilder, it looks like widgets have an onClose method you could use to do what you are trying to accomplish.

Communication to app container—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for Developers

Granted, I haven't tried this myself, but it might help.

View solution in original post

2 Replies
ReneRubalcava
Frequent Contributor II

For Web AppBuilder, it looks like widgets have an onClose method you could use to do what you are trying to accomplish.

Communication to app container—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for Developers

Granted, I haven't tried this myself, but it might help.

by Anonymous User
Not applicable

Oh Rene.. thank you. I got so buried in learning Dojo and Widget today.. oops.  Yes. This works perfectly and fires the alert:

onClose:

    function () {

        this.inherited(arguments);

        alert('close');

       

    }

I knew I had seen onClose somewhere. And then I searched all afternoon for it in Dojo because I thought it was part of Widget. Thanks!

0 Kudos