pub struct FormField {
pub name: String,
/* private fields */
}Expand description
A single form field: a name, a shared string value, and validation
rules. Cloning a FormField is cheap and shares state (D116 Phase 28
Step 8) — every clone reads/writes the SAME underlying atoms, the same
“clone shares identity” convention EditController/ScrollController
already use in this codebase. This is what lets TextInput::field(f),
Form::field(f), and the app’s own submit-button closure all see the
same live value/touched/errors without any manual synchronization.
Fields§
§name: StringImplementations§
Source§impl FormField
impl FormField
Sourcepub fn new(name: impl Into<String>) -> FormField
pub fn new(name: impl Into<String>) -> FormField
Plain constructor — the atoms it creates (use_atom) are NOT tied
to any component, so nothing rebuilds when they change. Call this
directly only when you don’t need live UI updates (e.g. a
throwaway validation check); for a real form field bound to a
widget, use FormField::for_ctx instead.
Sourcepub fn for_ctx(ctx: &mut Context, name: impl Into<String>) -> FormField
pub fn for_ctx(ctx: &mut Context, name: impl Into<String>) -> FormField
Create (or retrieve) a field persisted in component state — the
value/touched/errors survive rebuilds AND writing to them re-dirties
the owning component (so a submit button’s disabled state and an
inline error message actually refresh live). Follows the same hook
rules as ctx.state/ScrollController::for_ctx: call
unconditionally in build(), stable order.
pub fn with_value(self, v: impl Into<String>) -> FormField
pub fn rule(self, v: impl Validator) -> FormField
Sourcepub fn validate(&self) -> bool
pub fn validate(&self) -> bool
Run all validators against the current value, publish the result,
and return whether it passed. &self, not &mut self — every
clone of this field shares the same underlying atoms, so any
clone can validate and every other clone (and the app’s own
Form) sees the result immediately.
Sourcepub fn errors(&self) -> Vec<FieldError>
pub fn errors(&self) -> Vec<FieldError>
Current validation errors (from the last validate() call).
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
True if the field has no validation errors after the last
validate() call. Defaults to true before the first
validate() — an unvalidated field isn’t KNOWN invalid; callers
that need “definitely passes all rules” should call validate()
(or rely on Step 8’s live-validating .field() binding, which
validates on every edit) before trusting this for gating.
Sourcepub fn is_touched(&self) -> bool
pub fn is_touched(&self) -> bool
True if the field has been interacted with (set() called at
least once) — the standard “don’t show errors until touched”
convention, so a blank required field doesn’t show red before the
user has even had a chance to fill it in.