Skip to content

Commit e6b2f3d

Browse files
committed
rebase
1 parent ae395e2 commit e6b2f3d

3 files changed

Lines changed: 55 additions & 17 deletions

File tree

cot/src/form/fields.rs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,13 +1094,22 @@ mod tests {
10941094
},
10951095
PasswordFieldOptions {
10961096
max_length: Some(10),
1097+
min_length: Some(5),
1098+
size: Some(15),
1099+
autocomplete: Some(AutoComplete::Value("foo bar".to_string())),
1100+
placeholder: Some("Enter password".to_string()),
1101+
readonly: Some(false),
10971102
},
10981103
);
10991104
let html = field.to_string();
11001105
assert!(html.contains("type=\"password\""));
11011106
assert!(html.contains("required"));
11021107
assert!(html.contains("maxlength=\"10\""));
1108+
assert!(html.contains("minlength=\"5\""));
1109+
assert!(html.contains("autocomplete=\"foo bar\""));
1110+
assert!(html.contains("placeholder=\"Enter password\""));
11031111
}
1112+
11041113
#[cot::test]
11051114
async fn password_field_clean_value() {
11061115
let mut field = PasswordField::with_options(
@@ -1131,18 +1140,31 @@ mod tests {
11311140
required: true,
11321141
},
11331142
EmailFieldOptions {
1134-
min_length: Some(10),
1135-
max_length: Some(50),
1143+
max_length: Some(10),
1144+
min_length: Some(5),
1145+
size: Some(15),
1146+
autocomplete: Some(AutoComplete::Value("foo bar".to_string())),
1147+
dirname: Some("dir".to_string()),
1148+
list: Some(List::new(["foo@example.com", "baz@example.com"])),
1149+
placeholder: Some("Enter text".to_string()),
1150+
readonly: Some(true),
11361151
},
11371152
);
11381153

11391154
let html = field.to_string();
1155+
11401156
assert!(html.contains("type=\"email\""));
11411157
assert!(html.contains("required"));
1142-
assert!(html.contains("minlength=\"10\""));
1143-
assert!(html.contains("maxlength=\"50\""));
1158+
assert!(html.contains("minlength=\"5\""));
1159+
assert!(html.contains("maxlength=\"10\""));
11441160
assert!(html.contains("name=\"test_id\""));
11451161
assert!(html.contains("id=\"test_id\""));
1162+
assert!(html.contains("placeholder=\"Enter text\""));
1163+
assert!(html.contains("readonly"));
1164+
assert!(html.contains("autocomplete=\"foo bar\""));
1165+
assert!(html.contains("dirname=\"dir\""));
1166+
assert!(html.contains("list=\"__test_id_datalist\""));
1167+
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>"#));
11461168
}
11471169

11481170
#[cot::test]
@@ -1286,13 +1308,22 @@ mod tests {
12861308
IntegerFieldOptions {
12871309
min: Some(1),
12881310
max: Some(10),
1311+
placeholder: Some("Enter text".to_string()),
1312+
readonly: Some(false),
1313+
step: Some(Step::Value(10)),
12891314
},
12901315
);
12911316
let html = field.to_string();
1317+
12921318
assert!(html.contains("type=\"number\""));
12931319
assert!(html.contains("required"));
12941320
assert!(html.contains("min=\"1\""));
12951321
assert!(html.contains("max=\"10\""));
1322+
assert!(html.contains("step=\"10\""));
1323+
assert!(html.contains("placeholder=\"Enter text\""));
1324+
assert!(html.contains("name=\"test\""));
1325+
assert!(html.contains("id=\"test\""));
1326+
assert!(!html.contains("readonly"));
12961327
}
12971328

12981329
#[cot::test]
@@ -1434,13 +1465,22 @@ mod tests {
14341465
FloatFieldOptions {
14351466
min: Some(1.5),
14361467
max: Some(10.7),
1468+
placeholder: Some("Enter text".to_string()),
1469+
readonly: Some(true),
1470+
step: Some(Step::Any),
14371471
},
14381472
);
14391473
let html = field.to_string();
1474+
14401475
assert!(html.contains("type=\"number\""));
14411476
assert!(html.contains("required"));
14421477
assert!(html.contains("min=\"1.5\""));
14431478
assert!(html.contains("max=\"10.7\""));
1479+
assert!(html.contains("step=\"any\""));
1480+
assert!(html.contains("placeholder=\"Enter text\""));
1481+
assert!(html.contains("name=\"test\""));
1482+
assert!(html.contains("id=\"test\""));
1483+
assert!(html.contains("readonly"));
14441484
}
14451485

14461486
#[cot::test]

cot/src/form/fields/attrs.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ pub enum Dir {
101101

102102
impl Dir {
103103
pub fn as_str(&self) -> &'static str {
104-
match self{
104+
match self {
105105
Self::Rtl => "rtl",
106-
Self::Ltr => "ltr"
106+
Self::Ltr => "ltr",
107107
}
108108
}
109109
}
@@ -114,20 +114,17 @@ impl Display for Dir {
114114
}
115115
}
116116

117-
118-
119117
#[derive(Debug, Clone, Copy)]
120118
pub enum Capture {
121119
User,
122-
Environment
120+
Environment,
123121
}
124122

125-
126-
impl Capture{
123+
impl Capture {
127124
pub fn as_str(&self) -> &'static str {
128125
match self {
129126
Self::User => "user",
130-
Self::Environment => "environment"
127+
Self::Environment => "environment",
131128
}
132129
}
133130
}
@@ -136,4 +133,4 @@ impl Display for Capture {
136133
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
137134
f.write_str(self.as_str())
138135
}
139-
}
136+
}

cot/src/form/fields/files.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use bytes::Bytes;
55
use cot::form::{AsFormField, FormFieldValidationError};
66
use cot::html::HtmlTag;
77

8-
use crate::form::{FormField, FormFieldOptions, FormFieldValue, FormFieldValueError};
98
use crate::form::fields::attrs::Capture;
9+
use crate::form::{FormField, FormFieldOptions, FormFieldValue, FormFieldValueError};
1010

1111
#[derive(Debug)]
1212
/// A form field for a file.
@@ -66,7 +66,7 @@ pub struct FileFieldOptions {
6666
/// [`accept` attribute]: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/file#limiting_accepted_file_types
6767
pub accept: Option<Vec<String>>,
6868

69-
pub capture: Option<Capture>
69+
pub capture: Option<Capture>,
7070
}
7171

7272
impl Display for FileField {
@@ -212,7 +212,6 @@ mod tests {
212212
},
213213
FileFieldOptions {
214214
..Default::default()
215-
216215
},
217216
);
218217

@@ -248,7 +247,9 @@ mod tests {
248247
name: "test".to_owned(),
249248
required: true,
250249
},
251-
FileFieldOptions { ..Default::default() },
250+
FileFieldOptions {
251+
..Default::default()
252+
},
252253
);
253254

254255
let value = InMemoryUploadedFile::clean_value(&field);

0 commit comments

Comments
 (0)