Created
August 31, 2026 22:55
-
-
Save cocoa1231/3f84155f2ec9b3989f8dcd79c7b7ec83 to your computer and use it in GitHub Desktop.
minimal working example of lustre forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import lustre | |
| import gleam/io | |
| import gleam/list | |
| import lustre/attribute | |
| import lustre/element.{type Element} | |
| import lustre/element/html | |
| import lustre/event | |
| type Model = | |
| Int | |
| fn init(_) { | |
| 0 | |
| } | |
| type Message { | |
| UserClickedSubmit(formdata: List(#(String, String))) | |
| } | |
| fn update(m: Model, message: Message) -> Model { | |
| case message { | |
| UserClickedSubmit(data) -> { | |
| data | |
| |> list.map(fn(field) { | |
| let #(name, value) = field | |
| io.println("field name: " <> name) | |
| io.println("filed value: " <> value) | |
| }) | |
| m | |
| } | |
| } | |
| } | |
| fn view(_model: Model) -> Element(Message) { | |
| html.form([event.on_submit(UserClickedSubmit)], [ | |
| html.input([attribute.type_("file"), attribute.name("filepath")]), | |
| html.input([attribute.type_("submit")]) | |
| ]) | |
| } | |
| pub fn main() -> Nil { | |
| let app = lustre.simple(init, update, view) | |
| let assert Ok(_) = lustre.start(app, "#app", Nil) | |
| Nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment