Skip to main content

FormField

Struct FormField 

Source
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: String

Implementations§

Source§

impl FormField

Source

pub fn new(name: impl Into<String>) -> Self

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.

Source

pub fn for_ctx(ctx: &mut Context, name: impl Into<String>) -> Self

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.

Source

pub fn with_value(self, v: impl Into<String>) -> Self

Source

pub fn rule(self, v: impl Validator) -> Self

Source

pub fn get(&self) -> String

Current string value.

Source

pub fn set(&self, v: impl Into<String>)

Set the string value and mark the field touched.

Source

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.

Source

pub fn errors(&self) -> Vec<FieldError>

Current validation errors (from the last validate() call).

Source

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.

Source

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.

Source

pub fn reset(&self)

Reset value, errors, and touched state.

Trait Implementations§

Source§

impl Clone for FormField

Source§

fn clone(&self) -> FormField

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.