Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Executing JS scripts within events #783

Archmonger started this conversation in Ideas
Discussion options

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.

You must be logged in to vote

Replies: 3 comments 2 replies

Comment options

Can this be achieved with an adjacent script element that binds an onClick handler to the button?

You must be logged in to vote
1 reply
Comment options

Archmonger Jul 6, 2022
Maintainer Author

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>
Comment options

Extend the VDOM spec to allow for the following to occur

  • String based event handlers
  • idom.core.event based event handlers, that can access the serialized return attributes of some arbitrary javascript
You must be logged in to vote
1 reply
Comment options

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?

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /