pub struct MultiValueField {
pub name: String,
pub label: Option<String>,
pub required: bool,
pub help_text: Option<String>,
pub widget: Widget,
pub initial: Option<Value>,
pub fields: Vec<Box<dyn FormField>>,
pub require_all_fields: bool,
}Expand description
MultiValueField combines multiple fields into one
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.
fields: Vec<Box<dyn FormField>>The sub-fields that make up this composite field.
require_all_fields: boolWhether all sub-fields must have values.
Implementations§
Source§impl MultiValueField
impl MultiValueField
Sourcepub fn new(name: String, fields: Vec<Box<dyn FormField>>) -> Self
pub fn new(name: String, fields: Vec<Box<dyn FormField>>) -> Self
Create a new MultiValueField
§Examples
use reinhardt_forms::fields::MultiValueField;
use reinhardt_forms::fields::{CharField, IntegerField};
use reinhardt_forms::FormField;
use serde_json::json;
// Create a multi-value field combining name and age
let fields: Vec<Box<dyn FormField>> = vec![
Box::new(CharField::new("name".to_string())),
Box::new(IntegerField::new("age".to_string())),
];
let field = MultiValueField::new("person".to_string(), fields);
// Valid: both values provided
let result = field.clean(Some(&json!(["John Doe", 30])));
assert!(result.is_ok());Trait Implementations§
Source§impl FormField for MultiValueField
impl FormField for MultiValueField
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 MultiValueField
impl !RefUnwindSafe for MultiValueField
impl Send for MultiValueField
impl Sync for MultiValueField
impl Unpin for MultiValueField
impl UnsafeUnpin for MultiValueField
impl !UnwindSafe for MultiValueField
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