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 hidden: bool,
45 pub required: bool,
46}
47
48impl InputProps<'_> {
49 fn get_handler_string(&self, handlers: &EventHandlers) -> RUMString {
50 let mut handler_string = RUMString::default();
51
52 for (handler_name, handler_function) in handlers {
53 handler_string += &rumtk_format!(" {}={:?}", handler_name, handler_function);
54 }
55
56 handler_string
57 }
58
59 pub fn to_rumstring(&self) -> RUMString {
60 let default_text = RUMString::default();
61 rumtk_format!(
62 "{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}",
63 match &self.name {
64 Some(name) => rumtk_format!("id={:?}", name),
65 None => default_text.clone(),
66 },
67 match &self.name {
68 Some(name) => rumtk_format!("name={:?}", name),
69 None => default_text.clone(),
70 },
71 match &self.typ {
72 Some(typ) => rumtk_format!("type={:?}", typ),
73 None => default_text.clone(),
74 },
75 match &self.value {
76 Some(val) => rumtk_format!("value={:?}", val),
77 None => default_text.clone(),
78 },
79 match &self.max {
80 Some(val) => rumtk_format!("max={:?}", val),
81 None => default_text.clone(),
82 },
83 match &self.placeholder {
84 Some(placeholder) => rumtk_format!("placeholder={:?}", placeholder),
85 None => default_text.clone(),
86 },
87 match &self.pattern {
88 Some(pattern) => rumtk_format!("pattern={:?}", pattern),
89 None => default_text.clone(),
90 },
91 match &self.event_handlers {
92 Some(handlers) => self.get_handler_string(handlers),
93 None => default_text.clone(),
94 },
95 match self.max_length {
96 Some(max_length) => rumtk_format!("maxlength={:?}", max_length),
97 None => default_text.clone(),
98 },
99 match self.min_length {
100 Some(min_length) => rumtk_format!("minlength={:?}", min_length),
101 None => default_text.clone(),
102 },
103 match self.autocapitalize {
104 true => rumtk_format!("autocapitalize"),
105 false => default_text.clone(),
106 },
107 match self.autocomplete {
108 true => rumtk_format!("autocomplete"),
109 false => default_text.clone(),
110 },
111 match self.autocorrect {
112 true => rumtk_format!("autocorrect"),
113 false => default_text.clone(),
114 },
115 match self.autofocus {
116 true => rumtk_format!("autofocus"),
117 false => default_text.clone(),
118 },
119 match self.disabled {
120 true => rumtk_format!("disabled"),
121 false => default_text.clone(),
122 },
123 match self.hidden {
124 true => rumtk_format!("hidden"),
125 false => default_text.clone(),
126 },
127 match self.required {
128 true => rumtk_format!("required"),
129 false => default_text.clone(),
130 },
131 )
132 }
133
134 pub fn to_string(&self) -> String {
135 self.to_rumstring().to_string()
136 }
137}