pub enum Widget {
TextInput,
PasswordInput,
EmailInput,
NumberInput,
TextArea,
Select {
choices: Vec<(String, String)>,
},
CheckboxInput,
RadioSelect {
choices: Vec<(String, String)>,
},
DateInput,
DateTimeInput,
FileInput,
HiddenInput,
}Expand description
Field widget type
Variants§
TextInput
PasswordInput
EmailInput
NumberInput
TextArea
Select
CheckboxInput
RadioSelect
DateInput
DateTimeInput
FileInput
HiddenInput
Implementations§
Source§impl Widget
impl Widget
Sourcepub fn render_html(
&self,
name: &str,
value: Option<&str>,
attrs: Option<&HashMap<String, String>>,
) -> String
pub fn render_html( &self, name: &str, value: Option<&str>, attrs: Option<&HashMap<String, String>>, ) -> String
Renders the widget as HTML with XSS protection.
All user-controlled values (name, value, attributes, choices) are HTML-escaped to prevent Cross-Site Scripting (XSS) attacks.
§Examples
use reinhardt_forms::Widget;
let widget = Widget::TextInput;
let html = widget.render_html("username", Some("john_doe"), None);
assert!(html.contains("<input"));
assert!(html.contains("type=\"text\""));
assert!(html.contains("name=\"username\""));
assert!(html.contains("value=\"john_doe\""));§XSS Protection
use reinhardt_forms::Widget;
let widget = Widget::TextInput;
// Malicious input is escaped
let html = widget.render_html("field", Some("<script>alert('xss')</script>"), None);
assert!(!html.contains("<script>"));
assert!(html.contains("<script>"));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Widget
impl<'de> Deserialize<'de> for Widget
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Widget
impl RefUnwindSafe for Widget
impl Send for Widget
impl Sync for Widget
impl Unpin for Widget
impl UnsafeUnpin for Widget
impl UnwindSafe for Widget
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