Attach multiple events

7188
4
Jump to solution
01-27-2015 03:55 PM
RiverTaig1
Occasional Contributor

In my widget, I have successfully hooked up a dojo on-click listener to an HTML Select control using data-dojo-attach-event like so...

<select id="cboPaletteItemChooser" data-dojo-attach-event="onclick:myFunc" >

... more code ...

But what I really want to do is also add an event handler for the onchange event as well (in addition to onclick).  How can I add two or more event handlers?

something like this doesn't work

<select id="cboPaletteItemChooser" data-dojo-attach-event="onclick:myFunc;onchange:myFunc2" >

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

In the Dojo documentation, the section on Event Attachments uses a slightly different syntax.

This is a comma-delimited string of key/value pairs (separated by colon); the key is the native DOM event to attach a handler to, and the value is the name of your widget's method to execute when that event is fired.

data-dojo-attach-event="onmouseenter:_onHover,onmouseleave:_onUnhover,ondijitclick:_onClick"

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

River,

   I never figured out if this could be done so I just added the additional events in my code and not the html.

0 Kudos
RiverTaig1
Occasional Contributor

Thanks Robert - I'm such a Dojo and Javascript newbie, I'm not quite sure what that would look like.  Do you somehow attach an event handler in widget.js using Dojo?  Could you provide a code snip?

0 Kudos
KenBuja
MVP Esteemed Contributor

In the Dojo documentation, the section on Event Attachments uses a slightly different syntax.

This is a comma-delimited string of key/value pairs (separated by colon); the key is the native DOM event to attach a handler to, and the value is the name of your widget's method to execute when that event is fired.

data-dojo-attach-event="onmouseenter:_onHover,onmouseleave:_onUnhover,ondijitclick:_onClick"

RiverTaig1
Occasional Contributor

Thank you Ken - that worked perfectly.  I guess it was just the pattern of using semi-colons for css delimiters that had me confused.  Thanks for the link to the Dojo documentation too (it can be a little overwhelming!).

0 Kudos