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 ///
22 /// Public because `ui/tests/form/fn.rs` and
23 /// `example/src/page/form` read it through
24 /// `get_values()`.
25 pub values: Signal<HashMap<&'static str, String>>,
26 /// Per-field validation error, keyed by field name.
27 /// Empty string means "no error".
28 ///
29 /// Public because `ui/tests/form/fn.rs` and
30 /// `example/src/page/form` read it through
31 /// `get_errors()`.
32 pub errors: Signal<HashMap<&'static str, String>>,
33 /// Per-field "user has interacted with this field" flag.
34 ///
35 /// Public because `ui/tests/form/fn.rs` reads it
36 /// through `get_touched()`.
37 pub touched: Signal<HashSet<&'static str>>,
38 /// True while a `submit` handler is running. Render
39 /// `<button disabled: state.submitting().get()>` to
40 /// prevent double-submit.
41 ///
42 /// Public because `ui/tests/form/fn.rs` reads it
43 /// through `get_submitting()`.
44 pub submitting: Signal<bool>,
45}