Genie Discord forum

Author Avataryakir12
9/16/2023, 12:06:40 PM

Is there a way for us to link variables to specific keyboard events?

Author Avataryakir12
9/18/2023, 7:06:28 PM

Does anyone if it's possible?

Author AvatarPere
9/19/2023, 7:20:20 AM

Umm I don't think you can do that with variables, but we do have keyboard event detection

https://learn.genieframework.com/examples/reactive-ui/keypress-detection

Author Avataryakir12
9/19/2023, 8:31:38 AM

I do not know how I managed to miss that in the docs... Thank you! Any way I can have @on("keyup.enter", :keypress) work on a the whole page rather than just for a textfield?

Author AvatarPere
9/19/2023, 2:10:48 PM

you can attach events to any component. If you want to do the entire page, wrapt it in a div or something, and attach an event to it like this

using GenieFramework
@app begin

    @event :page_clicked begin
        println("page clicked")
    end
end
ui() = Html.div([h1("here's some text"), h3("and some more")], @on("click", :page_clicked))
@page("/", ui)
Author Avataryakir12
9/19/2023, 2:13:49 PM

This is brilliant!!! Thank you!