euv_ui/hook/form/struct.rs
1use super::*;
2
3/// The aggregate form state.
4///
5/// Constructed once per `<form>` via `App::use_form()`,
6/// threaded through the form's inputs and the submit
7/// handler. Cheap to `Clone` (the four internal signals are
8/// each `Copy`-by-pointer).
9///
10/// # Field reactivity
11///
12/// `values`, `errors`, `touched`, and `submitting` are all
13/// `Signal`s, so any `html!` body that calls
14/// `state.values().get()` (or any of the other three) inside
15/// its render closure re-renders when the corresponding
16/// signal changes. There is no manual subscribe API; the
17/// reactive read IS the subscription.
18#[derive(Clone, Data, New)]
19pub struct FormState {
20 /// Per-field current value, keyed by field name.
21 pub(crate) values: Signal<HashMap<&'static str, String>>,
22 /// Per-field validation error, keyed by field name.
23 /// Empty string means "no error".
24 pub(crate) errors: Signal<HashMap<&'static str, String>>,
25 /// Per-field "user has interacted with this field" flag.
26 pub(crate) touched: Signal<HashSet<&'static str>>,
27 /// True while a `submit` handler is running. Render
28 /// `<button disabled: state.submitting().get()>` to
29 /// prevent double-submit.
30 pub(crate) submitting: Signal<bool>,
31}