Skip to content

Commit 69188ae

Browse files
committed
LibWeb: Return custom validity error message
Previously, validation_message() always returned a hardcoded "Invalid form" string, now it correctly returns the custom validity error message when the element is suffering from a custom error. Other validation errors still return the "Invalid form" message.
1 parent 37f49d5 commit 69188ae

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

Libraries/LibWeb/HTML/FormAssociatedElement.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,18 @@ Utf16String FormAssociatedElement::validation_message() const
266266
if (!is_candidate_for_constraint_validation() || satisfies_its_constraints())
267267
return {};
268268

269-
// FIXME:
270269
// 2. Return a suitably localized message that the user agent would show the user if this were the only form
271270
// control with a validity constraint problem. If the user agent would not actually show a textual message in
272271
// such a situation (e.g., it would show a graphical cue instead), then return a suitably localized message that
273-
// expresses (one or more of) the validity constraint(s) that the control does not satisfy. If the element is a
274-
// candidate for constraint validation and is suffering from a custom error, then the custom validity error
275-
// message should be present in the return value.
272+
// expresses (one or more of) the validity constraint(s) that the control does not satisfy.
273+
274+
// If the element is a candidate for constraint validation and is suffering from a custom error, then
275+
// the custom validity error message should be present in the return value.
276+
if (suffering_from_a_custom_error()) {
277+
return Utf16String::from_utf8(m_custom_validity_error_message);
278+
}
279+
280+
// FIXME: Return more specific localized messages
276281
return "Invalid form"_utf16;
277282
}
278283

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Harness status: OK
2+
3+
Found 8 tests
4+
5+
8 Pass
6+
Pass [input] The validity.customError must be true if the custom validity error message is not empty
7+
Pass [input] The validity.customError must be false if the custom validity error message is empty
8+
Pass [button] The validity.customError must be true if the custom validity error message is not empty
9+
Pass [button] The validity.customError must be false if the custom validity error message is empty
10+
Pass [select] The validity.customError must be true if the custom validity error message is not empty
11+
Pass [select] The validity.customError must be false if the custom validity error message is empty
12+
Pass [textarea] The validity.customError must be true if the custom validity error message is not empty
13+
Pass [textarea] The validity.customError must be false if the custom validity error message is empty
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>The constraint validation API Test: element.validity.customError</title>
4+
<link rel="author" title="Intel" href="http://www.intel.com/">
5+
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-validitystate-customerror">
6+
<link rel="help" href="https://html.spec.whatwg.org/multipage/#the-constraint-validation-api">
7+
<script src="../../../../resources/testharness.js"></script>
8+
<script src="../../../../resources/testharnessreport.js"></script>
9+
<script src="support/validator.js"></script>
10+
<div id="log"></div>
11+
<script>
12+
var testElements = [
13+
{
14+
tag: "input",
15+
types: [],
16+
testData: [
17+
{conditions: {message: "My custom error"}, expected: true, name: "[target] The validity.customError must be true if the custom validity error message is not empty"},
18+
{conditions: {message: ""}, expected: false, name: "[target] The validity.customError must be false if the custom validity error message is empty"}
19+
]
20+
},
21+
{
22+
tag: "button",
23+
types: [],
24+
testData: [
25+
{conditions: {message: "My custom error"}, expected: true, name: "[target] The validity.customError must be true if the custom validity error message is not empty"},
26+
{conditions: {message: ""}, expected: false, name: "[target] The validity.customError must be false if the custom validity error message is empty"}
27+
]
28+
},
29+
{
30+
tag: "select",
31+
types: [],
32+
testData: [
33+
{conditions: {message: "My custom error"}, expected: true, name: "[target] The validity.customError must be true if the custom validity error message is not empty"},
34+
{conditions: {message: ""}, expected: false, name: "[target] The validity.customError must be false if the custom validity error message is empty"}
35+
]
36+
},
37+
{
38+
tag: "textarea",
39+
types: [],
40+
testData: [
41+
{conditions: {message: "My custom error"}, expected: true, name: "[target] The validity.customError must be true if the custom validity error message is not empty"},
42+
{conditions: {message: ""}, expected: false, name: "[target] The validity.customError must be false if the custom validity error message is empty"}
43+
]
44+
}
45+
]
46+
47+
validator.run_test(testElements, "customError");
48+
</script>

0 commit comments

Comments
 (0)