pub struct Form { /* private fields */ }Expand description
The reactive form. Cheap to clone (Rc-shared) and 'static, so it can
be captured by handlers. Field order is registration order.
Implementations§
Source§impl Form
impl Form
pub fn new(cx: &mut App) -> Self
Sourcepub fn field(
self,
cx: &mut App,
name: &'static str,
initial: impl Into<String>,
) -> Self
pub fn field( self, cx: &mut App, name: &'static str, initial: impl Into<String>, ) -> Self
Register a field with an initial value. Each field is a
Signal<String>; edits mark it touched, and a field carrying an error
re-validates live as it changes.
Sourcepub fn rule(self, name: &'static str, validator: Validator) -> Self
pub fn rule(self, name: &'static str, validator: Validator) -> Self
Attach a plain Validator to a field. Multiple rules run in order;
the first failure wins.
Sourcepub fn rule_form(self, name: &'static str, rule: Rule) -> Self
pub fn rule_form(self, name: &'static str, rule: Rule) -> Self
Attach a form-aware Rule (cross-field checks like
validators::equals_field).
Sourcepub fn signal(&self, name: &str) -> Signal<String>
pub fn signal(&self, name: &str) -> Signal<String>
The field’s value signal — plug it into TextInput::bind and friends.
Panics on an unregistered name (a typo you want loud).
Sourcepub fn errors(&self) -> Signal<HashMap<&'static str, String>>
pub fn errors(&self) -> Signal<HashMap<&'static str, String>>
The errors signal (field -> message). watch it to re-render on
validation changes.
pub fn value(&self, cx: &App, name: &str) -> String
pub fn set(&self, cx: &mut App, name: &str, value: impl Into<String>)
Sourcepub fn values(&self, cx: &App) -> FormValues
pub fn values(&self, cx: &App) -> FormValues
Every field’s current value, keyed by name.
Sourcepub fn error(&self, cx: &App, name: &str) -> Option<String>
pub fn error(&self, cx: &App, name: &str) -> Option<String>
The current error for a field, if any.
Sourcepub fn touched(&self, name: &str) -> bool
pub fn touched(&self, name: &str) -> bool
Whether the field has been edited since registration.
Sourcepub fn validate_field(&self, cx: &mut App, name: &'static str) -> bool
pub fn validate_field(&self, cx: &mut App, name: &'static str) -> bool
Run one field’s rules. Returns validity and updates the errors signal.
Sourcepub fn validate(&self, cx: &mut App) -> bool
pub fn validate(&self, cx: &mut App) -> bool
Run every field’s rules (in registration order). Returns whether all passed; the errors signal ends up reflecting exactly this pass.
Sourcepub fn submit(&self, cx: &mut App) -> Option<FormValues>
pub fn submit(&self, cx: &mut App) -> Option<FormValues>
Validate and hand back the values on success — the submit-handler one-liner.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Form
impl !Send for Form
impl !Sync for Form
impl !UnwindSafe for Form
impl Freeze for Form
impl Unpin for Form
impl UnsafeUnpin for Form
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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