-
-
Notifications
You must be signed in to change notification settings - Fork 328
Executing JS scripts within events #783
-
There's currently no existing capabilities for running a JS script from within an event tag.
I'm currently unsure what kind of API should exist for something like this though.
For example, perhaps it would look something like this?
@component def my_component(): return html.button( { "onClick": "$('.sidebar').toggle()" }, "This is a button!", )
In this scenario, providing a str within onClick would execute a one-time eval( ... ) on the client side.
This discussion will be converted to an issue after debating the API.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments 2 replies
-
Can this be achieved with an adjacent script element that binds an onClick handler to the button?
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes - But in my opinion that looks and feels quite awkward.
I think a string parameter for onClick (as seen above) feels intuitive. Especially since when writing raw HTML, one can typically do things such as
<button onclick="myFunction()">Click me</button>
Beta Was this translation helpful? Give feedback.
All reactions
-
Extend the VDOM spec to allow for the following to occur
- String based event handlers
idom.core.eventbased event handlers, that can access the serialized return attributes of some arbitrary javascript
Beta Was this translation helpful? Give feedback.
All reactions
-
Would it be possible to refer to idom components from within the JS string not via CSS (jQuery) but by their Python variable or idom-id?
Does somehting meaningful happen for { "onClick": (lambda e: html.script(...)) }? I think I could let the script write to a textarea-component and readout later / onChange?
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.