3.2.0

Event dispatching - V2

Hi Alex,
I have a question about event dispatching in AW. Please bare with me, this is a slightly
long post :(

'control.js' has an object called 'handlers' that has a list of functions to handle the various mouse events. At the moment I am interested in the 'onclick' handler. It seems to call a function 'RaiseControlEvent(onRowClicked, element, event)'
which in turn calls 'object.raiseEvent(handler, event, a, b, c)'.
(Incidentally, what are the 'a, b, c' arguments used for?)

raiseEvent is responsible for calling the actual event handler method that was defined on the object in question. So in my case, it calls 'grid.onRowClicked(event)'

Are these correct assumptions?

- Back now to the 'onclick' handler function.
It gets a reference to the parent element of the target node that was clicked and performs the same actions as listed above. This process loops around until it has checked all the ancestor nodes of the original target node. i.e. It seems to perform event bubbling back up the chain.

What I do not see during this dispatching process is a means of checking if bubbling of the event in question has been cancelled at some point by one of the handlers. Am I missing something here?

------- Reason for asking -------
I have a grid that when clicked (anywhere in a row) can open a new sub-grid (placed in a DIV that is appended as a child node of the row clicked element...'with thanks to Andreas for his excellent AW-v1 example') displaying another set of data...thus giving me the ability to have a grouped data effect.

Clicking on the new sub-grid can perform another action...display another set of sub-grouped data, display detailed info. about the selected row...whatever.
I click on a row in the sub-grid, that sub-grid processes the event, and then cancels bubbling of the event using the following function:

[code]
if (document.all) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}else if(e.preventDefault){
e.cancelBubble = true;
e.stopPropagation();
e.preventDefault();
}
return false;
[/code>

However, the parent grid still receives the event even after the code above is executed...and of course closes the sub-grid as it sees it as a toggle action. i.e. click a row once to open, click again to close.

Can you shed some light on this process for me please? I urgently need to get this working. I know that I can check the 'cancelBubble' property of the event in my own event handling code, but that's a bit hacky.
I would have thought that if I cancel bubbling I shouldn't receive this event any longer further up the document chain. Have I got this wrong?

Many thanks,
BT
BT
January 24,
The 'event manager' receives event at the very top (document level) when it has already bubbled through the document tree. It starts from the event source element and walks through the chain up again to check if there are any AW controls in this chain and triggers artificial AW events for them (like onRowClicked). Cancelling bubble at this point does not do anything because the event has already bubbled to the top. Now I see that this behavior is incorrect (I did not think of a possibility of nested controls) and the 'event manager' should check bubbling status of the event object at each step :-(

Possible workaround for 2.0b4 - instead of using artificial onRowClicked event assign an event handler to html onClick event with setEvent() method, like

obj.getRowTemplate().setEvent("onclick", ...);
Alex (ActiveWidgets)
January 24,
Cheers Alex. I appreciate the quick response! Are you going to change the behaviour of the 'event manager' to check for bubble cancel before the final release?

BT
BT
January 24,
Yes, I think the behavior should be the same as with 'native' events.
Alex (ActiveWidgets)
January 24,

This topic is archived.

See also:


Back to support forum