py-on*
event handler code is being executed at load time
#685
Labels
type: bug
Something isn't working
py-on*
event handler code is being executed at load time
#685
Checklist
What happened?
Py-event handler code being executed at page-load, which differs from Javascript in which the code is only executed when the event is received. i.e, in JS one would write
<button onClick="foo()">
, but in PysScript one would currently write<button py-onClick="foo">
This makes it the syntax for passing arguments to event functions different from Javascript in an unintuitive way.Consider the following examples, first Javascipt (JSFiddle), then in PyScript (JSFiddle), which I think the user would expect to do the same thing. (You made need to re-save them to get the JS to run):
The problem is, these two do not do the same thing. The py-onClick code is executed immediately on page-load, as the value of the py-on* attribute is evaluated directly.
After the page loads and the PyScript runtime initializes:
![image](https://user-images.githubusercontent.com/1931111/184413467-e712b1c9-7ef7-41ab-9286-7a6648250f06.png)
Proposed Solution
I suggest changing the behavior of py-on* events to match the Javascript syntax.
What browsers are you seeing the problem on? (if applicable)
No response
Console info
No response
Additional Context
This was spotted by user mark.d.lattimore on the Anaconda forums.
The text was updated successfully, but these errors were encountered: