-
Notifications
You must be signed in to change notification settings - Fork 9
Component Form
MeowLynxSea edited this page Jun 13, 2026
·
6 revisions
A composite that owns field values + errors and routes them to a single on_submit callback. The body of the form is built by child(...) calls passing field components (text inputs, selects, etc.).
use yororen_ui::headless::form::form;use yororen_ui::headless::form::form;
use yororen_ui::headless::text_input::text_input;
use yororen_ui::headless::label::label;
form("login", cx)
.value("email", self.email.clone())
.error("email", self.email_error.clone())
.on_submit({
let entity = cx.entity();
move |values, _window, cx| {
entity.update(cx, |s, _cx| {
s.email = values.get("email").cloned().unwrap_or_default();
s.submitted = true;
});
}
})
.submit("Sign in")
.child(text_input("email-field").placeholder("you@example.com").render(cx, window))
.child(label("email-hint", "Use your work email.", cx).render(cx))
.render(cx)| Method | Purpose |
|---|---|
value(field, v) |
Set the current value of field (a SharedString-able name). |
error(field, e) |
Set the current error message for field. |
on_submit(closure) |
Fn(HashMap<String, String>, &mut Window, &mut App) + 'static + Send + Sync. Fired when the form is submitted with the merged field values. |
submit(label) |
Add an auto-rendered submit button with the given label. |
submit_button(cx) |
Returns Option<AnyElement> — a pre-wired submit button (or None if submit was not set). |
trigger_submit(w, cx) |
Programmatically submit (e.g. from a keyboard shortcut). |
The body is built by .child(...) (the standard Div chain).
- Factory takes
(id, _cx). - No state entity — the parent view owns the values + errors (typically as
HashMap<String, String>). - The
on_submitcallback receives a freshHashMap<String, String>with the latest field values (the form gathers them from the children's state at submit time). - The
submit(...)builder adds a button to the form's children; you do not need to add it yourself. Usesubmit_button(cx)to get a handle to it (e.g. to control focus). -
.render(cx)returnsStateful<Div>.
TextInput, Form (next-steps), Modal
Yororen UI v0.3.0 · repository · Apache-2.0 · This wiki documents Yororen UI v0.3.0.
This wiki documents Yororen UI v0.3.0 — the headless-core, swappable-renderer build.