Genie Discord forum
Hello, I'm currently implementing a webpage using Genie. I have a button on my webpage and as soon as it gets pressed a julia function shall be executed.
The code and html looks similar to this:
`values = Dict(("A", 1), ("B", 2))
"<button class="add_button" onclick=$(interactively_add_view_element(values))> + ")
function interactively_add_view_element(values::Dict()) println(values"A") end`
However, the function is called when loading the page and not on the click event.
The reason why the code is executed when the page loads is because code interpolations with $(...) and <% ... %> are executed on load.
One way to trigger a function when a button is pressed is by binding it to a variable and executing code when the variable changes. Like this:
using GenieFramework @genietools vdict = Dict([("A", 1), ("B", 2)]) function interactively_add_view_element(vd) println(vd["A"]) end @handlers begin @in btn = false @onchange btn begin interactively_add_view_element(vdict) end end
<button class="add_button" v-on:click='btn = !btn'> +</button>
the syntax is
btn("Label", icon = "mail", @click(:btn))
It might be a problem that
btn is a fieldname and a function name, but I think that this case is already covered. If it is not working try renaming the button field to