List a widget’s events one can connect on
by Wolfram Kriesing

I saw it coming up a couple of times, now that I also needed it, let me share it.

The problem
You have a widget and want to connect, to some event of it. But you don’t know which events are there, what can I connect on and what’s the exact name.
Lets take a dijit.Dialog widget. What do I have to write in my dojo.connect(dialogWidget, “on???”, …) to connect to a certain event?

The solution
Let’s just find out what events the widget has to offer, by finding all methods that the widget has that start with “on”. Hehe pretty simple and basic, but it takes us there!
The following just grabs the first widget on the site that comes along (a dijit.Dialog doh :-) ) and lists all methods that start with “on”. Let’s see. Open your Firebug console and type ahead (or just paste, hehe):

>>> widget = dijit.byNode(dojo.query("[widgetid]")[0])
[Widget dijit.Dialog, inviteDialog] _connects=[3] _attaches=[0] id=overviewInviteDialog
>>> for (var i in widget) if (i.indexOf("on")==0) console.log(i)

Now you can do your dojo.connect() on whatever you think is right.

Tasty, ha?

This entry was posted on Wednesday, May 21st, 2008 at 11:21 am and is filed under Dojo Cookies. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

3 Responses to “List a widget’s events one can connect on”

  1. yoavrubin Says:

    good idea, what about the next step, which is finding a simple way to know what parameters are sent in each event?

  2. alex Says:


    So a couple of ideas spring to mind immediately. First, in Firefox there’s a working “uneval” function which can get you the source code for the function in question. Next, if it’s Dojo-specific class, you could use the module to query based on the instances’s declaredClass property. Lastly, on every browser you should be able to at least get the “.length” property of the function in question to see how many positional arguments it was declared with.


  3. dtynan Says:

    Using Firefox 3rc1 the above generates an error for me … anyone else see this? know how to get around it?

    >>> >>> widget = dijit.byNode(dojo.query(”[widgetid]“)[0])
    commandLine.evaluate FAILS: [Exception... "Security Manager vetoed action" nsresult: "0x80570027 (NS_ERROR_XPC_SECURITY_MANAGER_VETO)" location: "JS frame :: chrome://firebug/content/commandLine.js :: :: line 100" data: no]

Leave a Reply

You must be logged in to post a comment.