pub struct Form { /* private fields */ }Expand description
The validation report of a set of fields, in declaration order. Built by chaining
Form::field, then consulted. The values are recorded so that cross-field
validation is possible: one field compared with another.
Implementations§
Source§impl Form
impl Form
Sourcepub fn field(self, key: &'static str, value: &str, rule: Rule) -> Self
pub fn field(self, key: &'static str, value: &str, rule: Rule) -> Self
Validates value with rule and records the result under key.
Sourcepub fn field_with(
self,
key: &'static str,
value: &str,
check: impl Fn(&str, &Form) -> Option<String>,
) -> Self
pub fn field_with( self, key: &'static str, value: &str, check: impl Fn(&str, &Form) -> Option<String>, ) -> Self
Validates a field with a cross-field function receiving its value and the
partial form (the fields already declared): check(value, form) can consult
form.value(other) — a confirmed password, consistent dates, and
so on. So declare the referenced field first.
Sourcepub fn matches(
self,
key: &'static str,
value: &str,
other: &'static str,
message: impl Into<String>,
) -> Self
pub fn matches( self, key: &'static str, value: &str, other: &'static str, message: impl Into<String>, ) -> Self
A cross-field convenience: value must equal field other’s value (already
declared) — the “confirm the password” case. Otherwise message.
Sourcepub fn value(&self, key: &str) -> Option<&str>
pub fn value(&self, key: &str) -> Option<&str>
Field key’s recorded value, for cross-field validation.
Sourcepub fn errors(&self) -> Vec<(&'static str, &str)>
pub fn errors(&self) -> Vec<(&'static str, &str)>
Every error message as (key, message), in declaration order — for a summary
at the head of the form (see ErrorSummary).
Sourcepub fn first_invalid(&self) -> Option<&'static str>
pub fn first_invalid(&self) -> Option<&'static str>
The key of the first field in error (declaration order) — typically the one to focus or bring out on submission.