pub struct EmailField {
pub name: String,
pub label: Option<String>,
pub required: bool,
pub help_text: Option<String>,
pub widget: Widget,
pub initial: Option<Value>,
pub max_length: Option<usize>,
pub min_length: Option<usize>,
}Expand description
Email field with format validation
Fields§
§name: String§label: Option<String>§required: bool§help_text: Option<String>§widget: Widget§initial: Option<Value>§max_length: Option<usize>§min_length: Option<usize>Implementations§
Source§impl EmailField
impl EmailField
Sourcepub fn new(name: String) -> Self
pub fn new(name: String) -> Self
Create a new EmailField with the given name
§Examples
use reinhardt_forms::fields::EmailField;
let field = EmailField::new("email".to_string());
assert_eq!(field.name, "email");
assert!(!field.required);
assert_eq!(field.max_length, Some(320));Sourcepub fn required(self) -> Self
pub fn required(self) -> Self
Set the field as required
§Examples
use reinhardt_forms::fields::EmailField;
let field = EmailField::new("contact".to_string()).required();
assert!(field.required);Sourcepub fn with_max_length(self, max_length: usize) -> Self
pub fn with_max_length(self, max_length: usize) -> Self
Set the maximum length for the field
§Examples
use reinhardt_forms::fields::EmailField;
let field = EmailField::new("email".to_string()).with_max_length(100);
assert_eq!(field.max_length, Some(100));Sourcepub fn with_min_length(self, min_length: usize) -> Self
pub fn with_min_length(self, min_length: usize) -> Self
Set the minimum length for the field
§Examples
use reinhardt_forms::fields::EmailField;
let field = EmailField::new("email".to_string()).with_min_length(5);
assert_eq!(field.min_length, Some(5));Sourcepub fn with_label(self, label: impl Into<String>) -> Self
pub fn with_label(self, label: impl Into<String>) -> Self
Set the label for the field
§Examples
use reinhardt_forms::fields::EmailField;
let field = EmailField::new("contact_email".to_string()).with_label("Email Address");
assert_eq!(field.label, Some("Email Address".to_string()));Sourcepub fn with_help_text(self, help_text: impl Into<String>) -> Self
pub fn with_help_text(self, help_text: impl Into<String>) -> Self
Set the help text for the field
§Examples
use reinhardt_forms::fields::EmailField;
let field = EmailField::new("email".to_string()).with_help_text("We'll never share your email");
assert_eq!(field.help_text, Some("We'll never share your email".to_string()));Sourcepub fn with_initial(self, initial: impl Into<String>) -> Self
pub fn with_initial(self, initial: impl Into<String>) -> Self
Set the initial value for the field
§Examples
use reinhardt_forms::fields::EmailField;
let field = EmailField::new("email".to_string()).with_initial("user@example.com");
assert_eq!(field.initial, Some(serde_json::json!("user@example.com")));Trait Implementations§
Source§impl Clone for EmailField
impl Clone for EmailField
Source§fn clone(&self) -> EmailField
fn clone(&self) -> EmailField
Returns a duplicate of the value. Read more
1.0.0 · 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 EmailField
impl Debug for EmailField
Source§impl FormField for EmailField
impl FormField for EmailField
fn name(&self) -> &str
fn label(&self) -> Option<&str>
fn required(&self) -> bool
fn help_text(&self) -> Option<&str>
fn widget(&self) -> &Widget
fn initial(&self) -> Option<&Value>
fn clean(&self, value: Option<&Value>) -> FieldResult<Value>
Auto Trait Implementations§
impl Freeze for EmailField
impl RefUnwindSafe for EmailField
impl Send for EmailField
impl Sync for EmailField
impl Unpin for EmailField
impl UnsafeUnpin for EmailField
impl UnwindSafe for EmailField
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