question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Connect a function to a btn

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hhaenselcommented, Mar 8, 2021

I also enhanced @click a bit more by modifier and added some help text, maybe the first one in Stipple 🤣 Enjoy!

0reactions
yakir12commented, Mar 9, 2021

@yakir12 I really liked your idea for onbutton()

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 a R{Bool}. R{String} can often be an input 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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found