| 422 |
422 |
|
let _ = write!(out, " maxlength=\"{limit}\"");
|
| 423 |
423 |
|
}
|
| 424 |
424 |
|
push_bounds(out, field);
|
|
425 |
+ |
// The description asks for the wall-clock value to be submitted as the
|
|
426 |
+ |
// moment it names, and in a browser that conversion is script's: `<input
|
|
427 |
+ |
// type="datetime-local">` submits what the user typed and nothing in HTML
|
|
428 |
+ |
// turns it into an instant. So this emits the mark and quasi-webview's
|
|
429 |
+ |
// `instant.js` does the converting -- the same division as `data-clock`,
|
|
430 |
+ |
// where the markup says what to do and the shipped script is what a browser
|
|
431 |
+ |
// knows that a description cannot.
|
|
432 |
+ |
//
|
|
433 |
+ |
// Only DateTime. A date and a time are each half a moment and cannot name
|
|
434 |
+ |
// one on their own, so the flag is ignored there rather than emitting a
|
|
435 |
+ |
// mark nothing can honour.
|
|
436 |
+ |
if field.as_instant && matches!(field.kind, FieldKind::DateTime) {
|
|
437 |
+ |
out.push_str(" data-instant=\"true\"");
|
|
438 |
+ |
}
|
| 425 |
439 |
|
if field.invalid() {
|
| 426 |
440 |
|
out.push_str(" aria-invalid=\"true\"");
|
| 427 |
441 |
|
}
|
| 2127 |
2141 |
|
assert!(html.contains("class=\"mk-field\""), "{html}");
|
| 2128 |
2142 |
|
}
|
| 2129 |
2143 |
|
|
|
2144 |
+ |
#[test]
|
|
2145 |
+ |
fn a_datetime_asking_for_an_instant_is_marked_for_the_script_that_converts_it() {
|
|
2146 |
+ |
let mut f = field(FieldKind::DateTime);
|
|
2147 |
+ |
f.as_instant = true;
|
|
2148 |
+ |
let html = field_html(&f, &Filling::default(), &Emit::default());
|
|
2149 |
+ |
assert!(html.contains("data-instant=\"true\""), "{html}");
|
|
2150 |
+ |
// The control is unchanged: the flag says what is submitted, not what
|
|
2151 |
+ |
// is drawn.
|
|
2152 |
+ |
assert!(html.contains("type=\"datetime-local\""), "{html}");
|
|
2153 |
+ |
}
|
|
2154 |
+ |
|
|
2155 |
+ |
#[test]
|
|
2156 |
+ |
fn only_a_datetime_can_name_a_moment_so_only_a_datetime_is_marked() {
|
|
2157 |
+ |
for kind in [FieldKind::Date, FieldKind::Text, FieldKind::Number] {
|
|
2158 |
+ |
let mut f = field(kind);
|
|
2159 |
+ |
f.as_instant = true;
|
|
2160 |
+ |
let html = field_html(&f, &Filling::default(), &Emit::default());
|
|
2161 |
+ |
assert!(!html.contains("data-instant"), "{kind:?}: {html}");
|
|
2162 |
+ |
}
|
|
2163 |
+ |
}
|
|
2164 |
+ |
|
|
2165 |
+ |
#[test]
|
|
2166 |
+ |
fn a_datetime_that_did_not_ask_carries_no_mark() {
|
|
2167 |
+ |
let html = field_html(
|
|
2168 |
+ |
&field(FieldKind::DateTime),
|
|
2169 |
+ |
&Filling::default(),
|
|
2170 |
+ |
&Emit::default(),
|
|
2171 |
+ |
);
|
|
2172 |
+ |
assert!(!html.contains("data-instant"), "{html}");
|
|
2173 |
+ |
}
|
|
2174 |
+ |
|
| 2130 |
2175 |
|
#[test]
|
| 2131 |
2176 |
|
fn an_extended_field_says_so_and_leaves_the_disclosure_to_the_form() {
|
| 2132 |
2177 |
|
let mut f = field(FieldKind::Text);
|