pub struct ComboField {
pub name: String,
pub required: bool,
pub error_messages: HashMap<String, String>,
pub widget: Widget,
pub help_text: String,
pub initial: Option<Value>,
pub validators: Vec<Box<dyn FormField>>,
}Expand description
A field that combines multiple field validators
ComboField runs all provided validators in sequence and requires all to pass.
§Examples
use reinhardt_forms::fields::ComboField;
use reinhardt_forms::{Field, CharField, EmailField};
use serde_json::json;
let mut email_field = EmailField::new("email".to_string());
let mut char_field = CharField::new("email".to_string());
char_field.min_length = Some(5);
char_field.max_length = Some(100);
let field = ComboField::new("email")
.add_validator(Box::new(email_field))
.add_validator(Box::new(char_field));
let result = field.clean(Some(&json!("user@example.com")));
assert!(result.is_ok());
let result = field.clean(Some(&json!("not-an-email")));
assert!(result.is_err());
let result = field.clean(Some(&json!("a@b")));
assert!(result.is_err());Fields§
§name: String§required: bool§error_messages: HashMap<String, String>§widget: Widget§help_text: String§initial: Option<Value>§validators: Vec<Box<dyn FormField>>Implementations§
Source§impl ComboField
impl ComboField
Sourcepub fn add_validator(self, validator: Box<dyn FormField>) -> Self
pub fn add_validator(self, validator: Box<dyn FormField>) -> Self
Add a validator field
Trait Implementations§
Source§impl FormField for ComboField
impl FormField for ComboField
fn name(&self) -> &str
fn label(&self) -> Option<&str>
fn widget(&self) -> &Widget
fn required(&self) -> bool
fn initial(&self) -> Option<&Value>
fn help_text(&self) -> Option<&str>
fn clean(&self, value: Option<&Value>) -> FieldResult<Value>
Auto Trait Implementations§
impl Freeze for ComboField
impl !RefUnwindSafe for ComboField
impl Send for ComboField
impl Sync for ComboField
impl Unpin for ComboField
impl UnsafeUnpin for ComboField
impl !UnwindSafe for ComboField
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