Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#15026 closed defect (fixed)

double connect problem with non-templated widgets

Reported by: bill Owned by: bill
Priority: undecided Milestone: 1.8
Component: Parser Version: 1.7.2
Keywords: Cc:
Blocked By: Blocking:

Description

There's an issue with non-templated widgets instantiated by the parser where event handlers fire twice. The issue is with markup like:

<button data-dojo-type="MyButton" onClick="alert('hi');">click me</button>

The parser calls:

new MyButton({onClick: function(){ alert('hi'); });

And then the MyButton widget eventually does something like this:

on(this.domNode, "click",  function(){ alert('hi'); });

(Remember that it needs to call on() so pure programmatic creation works correctly.)

The problem is that there's still the original onclick handler that was setup on the DOMNode before dojo/dijit even entered the picture. Hence the alert triggers twice. Templated widgets get rid of the original onclick handler when they swap out the original <button> DOMNode, but behavioral widgets leave the <button> node and the original onclick handler there.

The solution suggested to me was for the parser to removeAttribute() any functions from the DOMNode. And that would work pretty well, unless there was some truly minimal widget that (for example) completely ignores it's parameters. This is the case that worries me a little bit, especially if the parser is smart enough to process onClick even if there's no MyButton.prototype.onClick() method.

But I don't see any alternative, other than telling people to use data-dojo-props="...", which isn't very degradable-friendly because it forces apps to repeat their onclick handler in two places.

Change History (3)

comment:1 Changed 8 years ago by bill

Milestone: tbd1.8
Status: newassigned

comment:2 Changed 8 years ago by bill

Resolution: fixed
Status: assignedclosed

In [28180]:

Solve problem of onclick etc. handlers getting called twice on behavioral widgets instantiated by the parser.

Also doing some AMD cleanup on the test case.

Fixes #15026 !strict.

comment:3 Changed 8 years ago by bill

In [28190]:

Fix fix to handlers getting called twice on IE, refs #15026 !strict.

Note: See TracTickets for help on using tickets.