pub enum Constraint<'a> {
MinLength(usize),
MaxLength(usize),
MinNumber(f64),
MaxNumber(f64),
MinDate(&'a str),
MaxDate(&'a str),
MinDateTime(&'a str),
MaxDateTime(&'a str),
MinTime(&'a str),
MaxTime(&'a str),
Pattern(&'a str),
Func(Box<dyn Fn(&Value) -> Result<(), ValidationError>>),
}
Expand description
Constraints on Field
values, perform validation.
All of the constraints cause server-side validation to be performed,
all except Constraint::Func
should - assuming they’re serialized
properly - result in client-side validation. HTML validity is checked
when adding the constraints to the fields using HtmlForm
’s builder
methods.
Variants§
MinLength(usize)
Constraint on most inputs.
MaxLength(usize)
Constraint on most inputs.
MinNumber(f64)
Constraint on number
and range
inputs.
MaxNumber(f64)
Constraint on number
and range
inputs.
MinDate(&'a str)
Constraint on date
input.
MaxDate(&'a str)
Constraint on date
input.
MinDateTime(&'a str)
Constraint on datetime-local
input.
MaxDateTime(&'a str)
Constraint on datetime-local
input.
MinTime(&'a str)
Constraint on time
input.
MaxTime(&'a str)
Constraint on time
input.
Pattern(&'a str)
Constraint on most Element::Input
fields, causes regex pattern
validation (both on the server and the client, note that the pattern
therefore must execute correctly on both sides).
Func(Box<dyn Fn(&Value) -> Result<(), ValidationError>>)
Constraint on any field, is executed server-side only and not serialized.
Implementations§
Source§impl<'a> Constraint<'a>
impl<'a> Constraint<'a>
Sourcepub fn validate(&self, formvalue: &Value) -> Result<(), ValidationError>
pub fn validate(&self, formvalue: &Value) -> Result<(), ValidationError>
Validate a single, non-empty Value
.
Sourcepub fn attrpair(&self) -> Option<(String, String)>
pub fn attrpair(&self) -> Option<(String, String)>
Returns the name and value of the HTML attribute of the Constraint.
Returns None for Constraint::Func
, as that is only functional on
the server side.
Sourcepub fn allowed_on(&self, element: &Element) -> bool
pub fn allowed_on(&self, element: &Element) -> bool
Return true if this Constraint
is allowed on element
,
false otherwise.