Skip to main content

FormController

Struct FormController 

Source
pub struct FormController { /* private fields */ }
Expand description

Controller-owned registry of form fields.

Owns every value signal and state cell; callers only receive FieldHandle accessors. Clones share the same underlying signals and memos, so there is exactly one source of truth per field value. Memos created owner-less (headless) are never disposed — acceptable because the controller lives for the form’s lifetime.

v0 fields anchor their state to a Value snapshot taken at registration; that snapshot anchors FieldHandle::dirty, FormController::reset, and the server-baseline comparison. Default registration snapshots the empty-string Value; FormController::register_initial and FormController::register_initial_with snapshot a caller-supplied value instead (for prefilled fields). The snapshot is immutable after registration.

Implementations§

Source§

impl FormController

Source

pub fn new(default_validate_on: ValidateOn) -> FormController

Creates a controller with the given default validation timing.

§Panics

Only if the registry mutex is poisoned by a panic in another thread holding it (never in normal use).

Source

pub fn register( &mut self, path: FieldPath, schema: Box<dyn DynSchema>, ) -> Result<FieldHandle, RegisterError>

Registers a field using the controller-default timing mode, rejecting duplicate paths (fail-fast at the bug site: a double render or copy-paste build surfaces here instead of forking state invisibly).

§Errors

Returns RegisterError::Duplicate if path is already registered.

Source

pub fn register_with( &mut self, path: FieldPath, schema: Box<dyn DynSchema>, validate_on: ValidateOn, ) -> Result<FieldHandle, RegisterError>

Registers a field with an explicit timing mode overriding the controller default.

§Errors

Returns RegisterError::Duplicate if path is already registered.

Source

pub fn register_initial( &mut self, path: FieldPath, schema: Box<dyn DynSchema>, initial: Value, ) -> Result<FieldHandle, RegisterError>

Registers a prefilled field using the controller-default timing mode, with initial as the dirty/reset/server-baseline anchor instead of the empty-string default. The snapshot is immutable after registration — no re-anchoring API exists.

initial is NOT validated against the field’s schema at registration time; if it violates constraints, the error memo reports those issues immediately (identical to registering then setting the value).

§Errors

Returns RegisterError::Duplicate if path is already registered; the existing field is left untouched.

Source

pub fn register_initial_with( &mut self, path: FieldPath, schema: Box<dyn DynSchema>, validate_on: ValidateOn, initial: Value, ) -> Result<FieldHandle, RegisterError>

Same as FormController::register_initial plus an explicit timing mode overriding the controller default, symmetric with FormController::register_with.

initial is NOT validated against the field’s schema at registration time; if it violates constraints, the error memo reports those issues immediately (identical to registering then setting the value).

§Errors

Returns RegisterError::Duplicate if path is already registered; the existing field is left untouched.

Source

pub fn field(&self, path: &FieldPath) -> Option<FieldHandle>

Looks up the handle for a registered path.

The returned handle is a cheap clone sharing the same underlying cells.

Source

pub fn effective_validate_on(&self, path: &FieldPath) -> Option<ValidateOn>

The resolved validation-timing mode for path, or None when the path is not registered.

Source

pub fn mark_touched(&self, path: &FieldPath)

Marks the field touched — the blur seam driving visibility gates.

Source

pub fn revalidate(&self, path: &FieldPath)

Eagerly evaluates the field’s error memos, synchronously — no await, no scheduling (FSV-2). Because the memos are lazy, any consumer read recomputes stale values on demand anyway; this only warms the memo caches so a later .get() finds fresh values already computed.

Source

pub fn submitted(&self) -> ArcRwSignal<bool>

The form-level submit-attempt flag feeding every display gate.

Source

pub fn is_submitting(&self) -> ArcRwSignal<bool>

The in-flight submit flag: true between the snapshot gate and the handler future settling, across success and failure alike.

Source

pub fn form_errors(&self) -> ArcMemo<Vec<FormaIssue>>

Reactive aggregate of every field’s display-gated issues plus form-level (unmatched) server issues.

Source

pub fn apply_server_errors(&self, error: &FormaError)

Merges server-side issues into field state. Issues addressed to registered paths REPLACE that field’s server cells; unknown or ROOT paths land in the form-level unmatched collection. A subsequent edit to a field hides its stale server issues until the next apply.

The known-path list and every field’s current value are captured under ONE registry acquisition, so a concurrent edit can never anchor a baseline to a value torn against a stale grouping snapshot; all signal writes happen after the lock is released.

Source

pub fn validate(&self) -> Result<(), FormaError>

Validates the whole form synchronously against each field’s schema.

Independent of display gates — a hidden (untouched) violation still fails submission.

§Errors

Returns every violated field’s issues, in declaration order, when any registered field fails.

Source

pub fn snapshot(&self) -> FormSnapshot

Takes a point-in-time copy of all field values in declaration order.

Source

pub fn on_submit<T, E, F, Fut>( &self, handler: F, ) -> impl Future<Output = Result<T, SubmitError<E>>>
where F: FnOnce(FormSnapshot) -> Fut, Fut: Future<Output = Result<T, E>>,

Composes the submit boundary as a plain future: whole-form sync validation first (a failure resolves with SubmitError::Validation and never constructs handler), then a FormSnapshot gate, is_submitting bracketing the attempt via a drop guard — the flag resets on success, handler error, validation failure, AND when the composed future is dropped (cancelled) mid-flight. No spawner required; the caller owns scheduling.

This never flips the FormController::submitted flag: the caller owns that (formars-ui’s form glue flips it before awaiting), so headless callers who skip the flip keep Submit-gated errors hidden.

Source

pub fn reset(&self)

Restores every field to its pristine registered state and clears all form-level (unmatched) server issues.

The FormController::submitted flag is deliberately NOT cleared: the caller owns it, mirroring FormController::on_submit (which never flips it).

Trait Implementations§

Source§

impl Clone for FormController

Source§

fn clone(&self) -> FormController

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<E, T, Request, Encoding> FromReq<Patch<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Post<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Put<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, Encoding, Response, T> FromRes<Patch<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Post<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Put<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<E, T, Encoding, Request> IntoReq<Patch<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Post<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Put<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, Response, Encoding, T> IntoRes<Patch<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<E, Response, Encoding, T> IntoRes<Post<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<E, Response, Encoding, T> IntoRes<Put<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<T> SerializableKey for T

Source§

fn ser_key(&self) -> String

Serializes the key to a unique string. Read more
Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more