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 that determines HTML rendering.
Variants§
TextInput
Single-line text input (<input type="text">).
PasswordInput
Password input that never renders its value (<input type="password">).
EmailInput
Email address input (<input type="email">).
NumberInput
Numeric input (<input type="number">).
TextArea
Multi-line text area (<textarea>).
Select
Dropdown select with predefined (value, label) choices (<select>).
CheckboxInput
Checkbox input (<input type="checkbox">).
RadioSelect
Radio button group with predefined (value, label) choices.
DateInput
Date picker input (<input type="date">).
DateTimeInput
Date and time picker input (<input type="datetime-local">).
FileInput
File upload input (<input type="file">).
HiddenInput
Hidden input for passing data without display (<input type="hidden">).
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>"));