pub struct JSONField {
pub name: String,
pub required: bool,
pub error_messages: HashMap<String, String>,
pub widget: Widget,
pub help_text: String,
pub initial: Option<Value>,
pub require_object: bool,
pub require_array: bool,
pub required_keys: Vec<String>,
pub max_depth: usize,
}Expand description
A form field for JSON data with optional schema validation.
Fields§
§name: StringThe field name used as the form data key.
required: boolWhether this field must be filled in.
error_messages: HashMap<String, String>Custom error messages keyed by error type.
widget: WidgetThe widget type used for rendering this field.
help_text: StringHelp text displayed alongside the field.
initial: Option<Value>Optional initial (default) value for the field.
require_object: boolWhether to validate JSON is an object (not array, string, etc.)
require_array: boolWhether to validate JSON is an array
required_keys: Vec<String>Required keys for JSON objects
max_depth: usizeMaximum nesting depth for JSON deserialization to prevent stack overflow
Implementations§
Source§impl JSONField
impl JSONField
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Create a new JSONField
§Examples
use reinhardt_forms::fields::JSONField;
let field = JSONField::new("config");
assert_eq!(field.name, "config");
assert!(field.required);Sourcepub fn help_text(self, text: impl Into<String>) -> Self
pub fn help_text(self, text: impl Into<String>) -> Self
Sets the help text displayed alongside the field.
Sourcepub fn require_object(self) -> Self
pub fn require_object(self) -> Self
Requires the JSON value to be an object.
Sourcepub fn require_array(self) -> Self
pub fn require_array(self) -> Self
Requires the JSON value to be an array.
Sourcepub fn required_keys(self, keys: Vec<String>) -> Self
pub fn required_keys(self, keys: Vec<String>) -> Self
Sets the list of keys that must be present in JSON objects.
Trait Implementations§
Source§impl FormField for JSONField
impl FormField for JSONField
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 JSONField
impl RefUnwindSafe for JSONField
impl Send for JSONField
impl Sync for JSONField
impl Unpin for JSONField
impl UnsafeUnpin for JSONField
impl UnwindSafe for JSONField
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