Connect a function to a btn
See original GitHub issueI’d like a Julia function to be called when the user presses a btn
, so for each btn
I have defined a model boolean parameter, and I use this custom flipon
function:
flipon(f::Function, r::R{Bool}) = on(r) do tf
if tf
f()
r[] = false
end
end
to then connect a function, f
, to that button.
For instance, to connect a save
function to a “Save” btn
, I have:
flipon(save, model.save)
Is there another obvious way I missed, or should we include this somehow?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Using an HTML button to call a JavaScript function
8 Answers 8 · 1: There's defining it in the HTML: <input id="clickMe" type="button" value="clickme" onclick="doFunction();" /> · 2: There's adding ...
Read more >onclick Event - W3Schools
The onclick event occurs when the user clicks on an HTML element. Mouse Events. Event, Occurs When. onclick, The user clicks on an...
Read more >How to call JavaScript function from HTML - Nathan Sebhastian
To call a JavaScript function from a button click, you need to add an event handler and listen for the click event from...
Read more >How to Call Function on Button Click in JavaScript?
Method 1: Use addEventListener() Method. Get the reference to the button. For example, using getElementById() method. Call addEventListener() function on ...
Read more >How To Call JavaScript Function On HTML Button Click
Inside Script region, find the HTML button by its ID and attach JS function. document.getElementById("btnClick").onclick = clickEvent; Now when button is ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I also enhanced
@click
a bit more by modifier and added some help text, maybe the first one in Stipple 🤣 Enjoy!Thanks! I like everything you guys do here…!
An alias for
R{Bool}
sounds useful but it makes me wonder about the other widgets, should they too get aliases? What about the fact that a toggle also is aR{Bool}
.R{String}
can often be aninput
but not always… This seems like it wouldn’t be very consistent. Unless someone has many buttons in their dashboard, this seems like it would only save the user extra typing when they define their model’s type.Another tempting shortcut (but again, with caveats) is to have the model be defined (even by a named tuple/dict) by the parameters’ names and default values alone (via a function). The parameter types can be collected from their defaults and since everything is an Observable we don’t need anything else than the names of the parameters and their default values. As a convenience function it seems fine, but it won’t allow for Inner Constructor Methods to be defined (I find it very useful to connect some of the parameters in the model to each other, when it gets initiated).