The code blow toggles the visibility of the “sub-links” when the user clicks on link_1 (good), but also when the user clicks on link_2 and link_3 (bad).
Is it possible to avoid the execution of link_1_click
when clicking on link_2
?
In a dashboard form I have the following links:

and the following code:
def link_1_click (self, **event_args):
self.toggle_links(event_args['sender'])
def toggle_links(self, parent_link):
for link in parent_link.get_components():
link.visible = not link.visible
def link_2_click (self, **event_args):
print 'link 2'
def link_3_click (self, **event_args):
print 'link 3'
(edit) - Don’t do this! See Meredydd’s comment below.
I can’t see a way to do the equivalent of the Javascript “event.stopPropagation();”
A workaround I use - which I admit is a little ungainly - is this. Link 1 is the parent and link 2 is the child :
def __init__(self, **properties):
self.init_components(**properties)
self.clicked=None
def link_1_click (self, **event_args):
print("Parent Link 1 Click Event")
if self.clicked is None:
self.clicked=self.link_1
self.perform_link_click(self.clicked)
self.clicked=None
def link_2_click (self, **event_args):
print("Child Link 2 Click Event")
self.clicked = self.link_2
def perform_link_click(self,olink, **rest):
# olink is the link that was actually clicked.
print("Processing "+str(olink.text))
I set the link that was actually clicked in the link’s own event handler (self.clicked).
Then in the parent link I check to see if self.clicked is set. If not, I set it to the parent link.
Then I call a general link_click handler.
Eek! I’d advise against doing this, David - it depends on the precise order in which the click
events go off, and that can be influenced by subtle factors including server calls, table access, and the phase of the moon.
Stefano: I’d recommend using a ColumnPanel, with a Link above and the other Links underneath, using Spacers to indent the inner links. Here’s an example:
https://anvil.works/ide#clone:AISTW7AMOU5YSGNG=YD4WNLMVYLDKX4I63BBZAR2F
Ah ok - noted! Guess I’ve just been lucky so far 
@meredydd But just out of interest - you can be sure that the clicked link’s event will fire first, can’t you, whether it’s a parent or a child?
No guarantees. That’s currently the way it works, unless you make a server call or something else blocking, in which case the parent event will fire while the blocking call is in progress. But it’s not (currently) guaranteed behaviour, so please don’t rely on it!
Understood. Thanks for the clarification.