pub struct FieldErrors<F = String>where
F: FormFields,{ /* private fields */ }Expand description
A refused submission, keyed by the form whose fields it names.
Resource::validate_record answers a
FieldErrors<UserForm>, keyed by its record form, so an error always names a field the form
renders; one on an embedded value renders under its first control. An error picks its field
off the form’s keys:
use tablo_core::FieldErrors;
fn validate(form: &UserForm) -> FieldErrors<UserForm> {
let mut errors = FieldErrors::<UserForm>::new();
if form.age < 0 {
errors.add(|f| f.age, "Age must be zero or more");
}
errors
}The panel keys every error by the form key it renders under (FieldErrors, keyed by
String), and Source::form reads them back when a schema renders.
Implementations§
Source§impl<F> FieldErrors<F>where
F: FormFields,
impl<F> FieldErrors<F>where
F: FormFields,
Sourcepub fn new() -> FieldErrors<F>
pub fn new() -> FieldErrors<F>
No errors.
Sourcepub fn add(
&mut self,
pick: impl FnOnce(<F as FormFields>::Keys) -> <F as FormFields>::Field,
message: impl Into<Text>,
)
pub fn add( &mut self, pick: impl FnOnce(<F as FormFields>::Keys) -> <F as FormFields>::Field, message: impl Into<Text>, )
Refuse the field pick picks off the form’s keys with message:
errors.add(|f| f.age, "Age must be zero or more").
Sourcepub fn add_field(
&mut self,
field: impl Into<<F as FormFields>::Field>,
message: impl Into<Text>,
)
pub fn add_field( &mut self, field: impl Into<<F as FormFields>::Field>, message: impl Into<Text>, )
Refuse field with message, the field named directly: the panel’s own errors name a
form key, errors.add_field("email", ..).
Sourcepub fn push(&mut self, error: FieldError<<F as FormFields>::Field>)
pub fn push(&mut self, error: FieldError<<F as FormFields>::Field>)
Refuse error’s key with error.
Sourcepub fn iter(
&self,
) -> impl Iterator<Item = &FieldError<<F as FormFields>::Field>>
pub fn iter( &self, ) -> impl Iterator<Item = &FieldError<<F as FormFields>::Field>>
Every error, in the order it was added.
Sourcepub fn extend(&mut self, other: FieldErrors<F>)
pub fn extend(&mut self, other: FieldErrors<F>)
Append other’s errors after these.
Source§impl FieldErrors
impl FieldErrors
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Whether any error renders under key.
Sourcepub fn first(&self, key: &str) -> Option<&FieldError>
pub fn first(&self, key: &str) -> Option<&FieldError>
The error key renders: the first one added.
Trait Implementations§
Source§impl<F> Clone for FieldErrors<F>
impl<F> Clone for FieldErrors<F>
Source§fn clone(&self) -> FieldErrors<F>
fn clone(&self) -> FieldErrors<F>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more