rumtk_web/components/form/
props.rs1use rumtk_core::strings::{rumtk_format, RUMString};
24
25type EventHandler<'a> = (&'a str, &'a str);
26type EventHandlers<'a> = Vec<EventHandler<'a>>;
27
28#[derive(Debug, Clone, Default)]
29pub struct InputProps<'a> {
30 pub name: Option<RUMString>,
31 pub typ: Option<RUMString>,
32 pub value: Option<RUMString>,
33 pub max: Option<RUMString>,
34 pub placeholder: Option<RUMString>,
35 pub pattern: Option<RUMString>,
36 pub event_handlers: Option<EventHandlers<'a>>,
37 pub max_length: Option<usize>,
38 pub min_length: Option<usize>,
39 pub autocapitalize: bool,
40 pub autocomplete: bool,
41 pub autocorrect: bool,
42 pub autofocus: bool,
43 pub disabled: bool,
44 pub required: bool,
45}
46
47impl InputProps<'_> {
48 fn get_handler_string(&self, handlers: &EventHandlers) -> RUMString {
49 let mut handler_string = RUMString::default();
50
51 for (handler_name, handler_function) in handlers {
52 handler_string += &rumtk_format!(" {}={:?}", handler_name, handler_function);
53 }
54
55 handler_string
56 }
57
58 pub fn to_rumstring(&self) -> RUMString {
59 let default_text = RUMString::default();
60 rumtk_format!(
61 "{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}",
62 match &self.name {
63 Some(name) => rumtk_format!("id={:?}", name),
64 None => default_text.clone(),
65 },
66 match &self.name {
67 Some(name) => rumtk_format!("name={:?}", name),
68 None => default_text.clone(),
69 },
70 match &self.typ {
71 Some(typ) => rumtk_format!("type={:?}", typ),
72 None => default_text.clone(),
73 },
74 match &self.value {
75 Some(val) => rumtk_format!("value={:?}", val),
76 None => default_text.clone(),
77 },
78 match &self.max {
79 Some(val) => rumtk_format!("max={:?}", val),
80 None => default_text.clone(),
81 },
82 match &self.placeholder {
83 Some(placeholder) => rumtk_format!("placeholder={:?}", placeholder),
84 None => default_text.clone(),
85 },
86 match &self.pattern {
87 Some(pattern) => rumtk_format!("pattern={:?}", pattern),
88 None => default_text.clone(),
89 },
90 match &self.event_handlers {
91 Some(handlers) => self.get_handler_string(handlers),
92 None => default_text.clone(),
93 },
94 match self.max_length {
95 Some(max_length) => rumtk_format!("maxlength={:?}", max_length),
96 None => default_text.clone(),
97 },
98 match self.min_length {
99 Some(min_length) => rumtk_format!("minlength={:?}", min_length),
100 None => default_text.clone(),
101 },
102 match self.autocapitalize {
103 true => rumtk_format!("autocapitalize"),
104 false => default_text.clone(),
105 },
106 match self.autocomplete {
107 true => rumtk_format!("autocomplete"),
108 false => default_text.clone(),
109 },
110 match self.autocorrect {
111 true => rumtk_format!("autocorrect"),
112 false => default_text.clone(),
113 },
114 match self.autofocus {
115 true => rumtk_format!("autofocus"),
116 false => default_text.clone(),
117 },
118 match self.disabled {
119 true => rumtk_format!("disabled"),
120 false => default_text.clone(),
121 },
122 match self.required {
123 true => rumtk_format!("required"),
124 false => default_text.clone(),
125 },
126 )
127 }
128
129 pub fn to_string(&self) -> String {
130 self.to_rumstring().to_string()
131 }
132}