dojo widget won't emit event

I have a custom dojo widget that I need to listen for an event on another 3rd party widget and then emit that an event with the event object to another custom widget. For some reason, my custom widget is not emitting the event or the event is not registering properly with my second custom widget.

Here is the event-related code in my 1st custom widget:

onSelectComplete : function(evt) {
    // this custom widget inherits from dojo/Evented.  I've tried using this.emit and I've tried inheriting from _WidgetBase
    on.emit(self, "select", evt);
},

startDrawing : function() {

    //self._drawToolbar is the 3rd party widget from an API
    self._drawToolbar.activate(Draw.POLYGON);

    self._drawEndHandle = self._drawToolbar.on("draw-end", self.onSelectComplete);

 },

Here is the listener in my 2nd custom widget:

on(self._selector, "select", function(evt) {
    console.log(evt);
});

For the listener, I've tried listening for onSelectComplete, selectComplete, SelectComplete, selectcomplete, select-complete and none have worked. I've also tried using aspect.after instead of on, but that also didn't work. I was able to determine while debugging that the onSelectComplete of the 1st custom widget is being called correctly.

I'm stuck...

Answers


Sorry I didn't provide the answer sooner, but I did discover a solution.

Instead of having my dojo module inherit from dojo/Evented, I made it inherit from dijit/_WidgetBase. By doing so, my custom dojo module/widget now implements the on function.

So in my 1st widget I have an empty function called onSelectComplete : function (evt) {}, which I call when I want to emit the event.

And in my 2nd widget my code is:

on(self._selector, "selectComplete", function(evt) {
    console.log(evt);
});

Do make things clear: The onXXX functions was the old way to emit. I was fine with it, but it is deprecated!

What the hell is 'self'? Did you mean: 'this'?

Any widget inheriting from dojo/Evented can

on.emit(this, "select", {anyProperty: 'will be mixed in the event'});

The above is bubbling up which seems to be what you want to do ?

You could also do

this.emit("select", {anyProperty: 'will be mixed in the event'});

But this is only triggered once and not bubbled up.

From any other widget you can subscribe as you stated. Tell me if you need a working example.


Need Your Help

Dojo 1.7: BorderContainer and ContentPanes not working inside of a custom widget template

dojo

This is similar to a question already on here but I'm using Dojo 1.7. So, I can't get BorderContainer and ContentPanes working inside of a custom widget template. It's driving me mad. I tried addi...