pub struct DurationField {
pub name: String,
pub required: bool,
pub error_messages: HashMap<String, String>,
pub widget: Widget,
pub help_text: String,
pub initial: Option<Value>,
}Expand description
A field for ISO 8601 duration validation
Validates that the input is a valid ISO 8601 duration format (e.g., “P1Y2M3DT4H5M6S”).
§Examples
use reinhardt_forms::fields::DurationField;
use reinhardt_forms::Field;
use serde_json::json;
let field = DurationField::new("duration");
// Valid duration
let result = field.clean(Some(&json!("P1Y2M3DT4H5M6S")));
assert!(result.is_ok());
// Another valid duration (1 day)
let result = field.clean(Some(&json!("P1D")));
assert!(result.is_ok());Fields§
§name: StringThe field name used as the form data key.
required: boolWhether this field must be filled in.
error_messages: HashMap<String, String>Custom error messages keyed by error type.
widget: WidgetThe widget type used for rendering this field.
help_text: StringHelp text displayed alongside the field.
initial: Option<Value>Optional initial (default) value for the field.
Implementations§
Source§impl DurationField
impl DurationField
Trait Implementations§
Source§impl Clone for DurationField
impl Clone for DurationField
Source§fn clone(&self) -> DurationField
fn clone(&self) -> DurationField
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DurationField
impl Debug for DurationField
Source§impl FormField for DurationField
impl FormField for DurationField
Source§fn initial(&self) -> Option<&Value>
fn initial(&self) -> Option<&Value>
Returns the initial (default) value for this field, if any.
Source§fn clean(&self, value: Option<&Value>) -> FieldResult<Value>
fn clean(&self, value: Option<&Value>) -> FieldResult<Value>
Validates and cleans the submitted value, returning the cleaned result.
Auto Trait Implementations§
impl Freeze for DurationField
impl RefUnwindSafe for DurationField
impl Send for DurationField
impl Sync for DurationField
impl Unpin for DurationField
impl UnsafeUnpin for DurationField
impl UnwindSafe for DurationField
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
Mutably borrows from an owned value. Read more