pub struct DecimalField {Show 13 fields
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<f64>,
pub min_value: Option<f64>,
pub max_digits: Option<usize>,
pub decimal_places: Option<usize>,
pub localize: bool,
pub locale: Option<String>,
pub use_thousands_separator: bool,
}Expand description
DecimalField for decimal number input with digit and precision validation.
Precision Note: This field stores values internally as f64 (IEEE 754),
which provides approximately 15-17 significant decimal digits of precision.
All digit count and decimal place validations are performed on the string
representation before conversion to f64, ensuring accurate constraint
enforcement even for values that cannot be exactly represented in binary
floating-point.
For applications requiring exact decimal arithmetic (e.g., financial
calculations), consider using rust_decimal::Decimal in your application
layer after form validation.
Fields§
§name: StringThe field name used as the form data key.
label: Option<String>Optional human-readable label for display.
required: boolWhether this field must be filled in.
help_text: Option<String>Optional help text displayed alongside the field.
widget: WidgetThe widget type used for rendering this field.
initial: Option<Value>Optional initial (default) value for the field.
max_value: Option<f64>Maximum allowed value.
min_value: Option<f64>Minimum allowed value.
max_digits: Option<usize>Maximum total number of digits allowed.
decimal_places: Option<usize>Maximum number of digits after the decimal point.
localize: boolWhether to apply locale-aware formatting.
locale: Option<String>The locale to use for formatting (e.g., “en_US”).
use_thousands_separator: boolWhether to display thousands separators.
Implementations§
Source§impl DecimalField
impl DecimalField
Sourcepub fn new(name: String) -> Self
pub fn new(name: String) -> Self
Create a new DecimalField
§Examples
use reinhardt_forms::fields::DecimalField;
let field = DecimalField::new("price".to_string());
assert_eq!(field.name, "price");
assert!(field.required);Sourcepub fn with_localize(self, localize: bool) -> Self
pub fn with_localize(self, localize: bool) -> Self
Enables or disables locale-aware formatting.
Sourcepub fn with_locale(self, locale: String) -> Self
pub fn with_locale(self, locale: String) -> Self
Sets the locale for number formatting.
Sourcepub fn with_thousands_separator(self, use_separator: bool) -> Self
pub fn with_thousands_separator(self, use_separator: bool) -> Self
Enables or disables thousands separator display.
Trait Implementations§
Source§impl Clone for DecimalField
impl Clone for DecimalField
Source§fn clone(&self) -> DecimalField
fn clone(&self) -> DecimalField
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more