pub struct IntegerField {
pub name: String,
pub label: Option<String>,
pub required: bool,
pub help_text: Option<String>,
pub widget: Widget,
pub initial: Option<Value>,
pub max_value: Option<i64>,
pub min_value: Option<i64>,
}Expand description
Integer field with range validation
Fields§
§name: String§label: Option<String>§required: bool§help_text: Option<String>§widget: Widget§initial: Option<Value>§max_value: Option<i64>§min_value: Option<i64>Implementations§
Source§impl IntegerField
impl IntegerField
Sourcepub fn new(name: String) -> Self
pub fn new(name: String) -> Self
Create a new IntegerField with the given name
§Examples
use reinhardt_forms::fields::IntegerField;
let field = IntegerField::new("age".to_string());
assert_eq!(field.name, "age");
assert!(!field.required);
assert_eq!(field.min_value, None);Sourcepub fn required(self) -> Self
pub fn required(self) -> Self
Set the field as required
§Examples
use reinhardt_forms::fields::IntegerField;
let field = IntegerField::new("age".to_string()).required();
assert!(field.required);Sourcepub fn with_min_value(self, min_value: i64) -> Self
pub fn with_min_value(self, min_value: i64) -> Self
Set the minimum value for the field
§Examples
use reinhardt_forms::fields::IntegerField;
let field = IntegerField::new("age".to_string()).with_min_value(0);
assert_eq!(field.min_value, Some(0));Sourcepub fn with_max_value(self, max_value: i64) -> Self
pub fn with_max_value(self, max_value: i64) -> Self
Set the maximum value for the field
§Examples
use reinhardt_forms::fields::IntegerField;
let field = IntegerField::new("count".to_string()).with_max_value(100);
assert_eq!(field.max_value, Some(100));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::IntegerField;
let field = IntegerField::new("age".to_string()).with_label("Age");
assert_eq!(field.label, Some("Age".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::IntegerField;
let field = IntegerField::new("age".to_string()).with_help_text("Enter your age");
assert_eq!(field.help_text, Some("Enter your age".to_string()));Sourcepub fn with_initial(self, initial: i64) -> Self
pub fn with_initial(self, initial: i64) -> Self
Set the initial value for the field
§Examples
use reinhardt_forms::fields::IntegerField;
let field = IntegerField::new("quantity".to_string()).with_initial(1);
assert_eq!(field.initial, Some(serde_json::json!(1)));Trait Implementations§
Source§impl Clone for IntegerField
impl Clone for IntegerField
Source§fn clone(&self) -> IntegerField
fn clone(&self) -> IntegerField
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 IntegerField
impl Debug for IntegerField
Source§impl FormField for IntegerField
impl FormField for IntegerField
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 IntegerField
impl RefUnwindSafe for IntegerField
impl Send for IntegerField
impl Sync for IntegerField
impl Unpin for IntegerField
impl UnsafeUnpin for IntegerField
impl UnwindSafe for IntegerField
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