Skip to content

Commit 4824f19

Browse files
committed
wrap input and datalist in a div
1 parent a810fdd commit 4824f19

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

cot/src/form/fields.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ pub struct EmailFieldOptions {
298298
impl Display for EmailField {
299299
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
300300
let mut tag = HtmlTag::input("email");
301+
let mut data_list: Option<HtmlTag> = None;
302+
301303
tag.attr("name", self.id());
302304
tag.attr("id", self.id());
303305
if self.options.required {
@@ -333,8 +335,7 @@ impl Display for EmailField {
333335
let list_id = format!("__{}_datalist", self.id());
334336
tag.attr("list", &list_id);
335337

336-
let data_list = HtmlTag::data_list(list.clone(), &list_id);
337-
tag.push_tag(data_list);
338+
data_list = Some(HtmlTag::data_list(list.clone(), &list_id));
338339
}
339340
if let Some(multiple) = self.custom_options.multiple {
340341
if multiple {
@@ -346,6 +347,14 @@ impl Display for EmailField {
346347
tag.attr("value", value);
347348
}
348349

350+
if let Some(data_list) = data_list {
351+
let mut wrapper = HtmlTag::new("div");
352+
wrapper
353+
.attr("id", format!("__{}_datalist_wrapper", self.id()))
354+
.push_tag(tag)
355+
.push_tag(data_list);
356+
return write!(f, "{}", wrapper.render());
357+
}
349358
write!(f, "{}", tag.render())
350359
}
351360
}
@@ -1098,7 +1107,7 @@ mod tests {
10981107
assert!(html.contains("autocomplete=\"foo bar\""));
10991108
assert!(html.contains("dirname=\"dir\""));
11001109
assert!(html.contains("list=\"__test_id_datalist\""));
1101-
assert!(html.contains(r#"<datalist id="__test_id_datalist"><option value="foo@example.com"/><option value="baz@example.com"/></datalist>"#));
1110+
assert!(html.contains(r#"<datalist id="__test_id_datalist"><option value="foo@example.com">foo@example.com</option><option value="baz@example.com">baz@example.com</option></datalist>"#));
11021111
}
11031112

11041113
#[test]

cot/src/html.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ impl HtmlTag {
197197

198198
for l in list.into() {
199199
let mut option = HtmlTag::new("option");
200-
option.attr("value", l);
200+
option.attr("value", &l);
201+
option.push_str(&l);
201202
options.push(HtmlNode::Tag(option));
202203
}
203204

0 commit comments

Comments
 (0)