Widgets onclick gets called on the document DOM

7
I've written a widget that has a mendix.widget._Button that displays odd behaviour. Code: this.dynamicButton = new mendix.widget._Button({ caption : this.ButtonLabel, icon : this.ButtonIcon, cssclass : this.gridSubmitClass }); var handle = dojo.connect(dojo.query('.'+this.gridSubmitClass)[0], "onclick", dojo.hitch(this, this._OnSubmitMicroflow)); ...and in my uninitialize method I disconnect the _OnSubmitMicroflow. Assumptions The button is the only element with a class of "this.gridSubmitClass" Symptoms I am unable to reproduce this myself, but at a client of ours, it seems that the _OnSubmitMicroflow fires off when you click on ANY other widget, even Pop-up dialog messages. When I look at the event's target, it seems that random DOM objects are calling this method everytime there is a Mouse click event on the form. No where else is this microflow or event function remotely referenced other than illustrated at top. So I am stumped at what could be causing this? Any ideas suggestions?
asked
2 answers
4

I am not sure how an event handler connected to a specific DOM node could be fired off by clicking on other DOM nodes. Are you sure dojo.query always gives you the button's DOM node?

To make sure the event handler is connected to the right DOM node, it would be easier to use the reference to the button's DOM node you already have, instead of searching the entire DOM with dojo.query (by using this.connect the handler is automatically called with widget scope, and the connect is disconnected on destroy):

this.connect(this.dynamicButton.domNode, "click", this._OnSubmitMicroflow);

It would be even better to directly pass a click handler as parameter to the _Button's constructor (it would be great if there would be documentation for widgets such as _Button):

this.dynamicButton = new mendix.widget._Button({
    caption : this.ButtonLabel,
    action : dojo.hitch(this, "_OnSubmitMicroflow")
});

This way, the handler will also be called when the button has the focus and [enter] is pressed.

answered
0

I should connect by instance dojo.query('#' + id of the widget) or directly to this.dynamicButton.

Edit (avoid mistakes): I should connect by instance dojo.byId(id of the widget) or directly to this.dynamicButton.

answered