Closed lordvlad closed 3 years ago
Hi lordvlad,
Do you have an example on how to use the target feature? I'm looking for a way to know which element is calling the event (the idea is to have some icons and the same method i.e. on_click and perform some actions depending on the element that is calling the on_click method).
Thanks++!
this feature is not merged yet, but once merged, you could do
from ipywidgets import Label, HTML, HBox, Image, VBox, Box, HBox
from ipyevents import Event
from IPython.display import display
l = HTML('''
<button id=eeny>eeny</button>
<button id=meeny>meeny</button>
<button id=miny>miny</button>
<button id=moe>moe</button>
''')
h = HTML('Event info')
d = Event(source=l, watched_events=['click'])
def handle_event(event):
h.value = "You clicked %s" % event["target"]["id"]
d.on_dom_event(handle_event)
display(l, h)
bump
@lordvlad -- sorry it took roughly forever to respond to this. I added some explanation to the demo notebook -- does that look good to you?
looks great! thanks
Thanks, @lordvlad, merging -- I should have this released by Friday.
@lordvlad -- this has been released in 0.9.0. I'm planning to release the first stable version, 2.0.0, tomorrow.
0.9.0 supports jlab 2 and 3. The stable release will support only jlab3 and higher.
Quick and easy fix for #51
For now, the
event
object has another dictionary added at the keytarget
, containing (for now) only the tag name, id and class name of the target element.