diff --git a/Libraries/LibWeb/HTML/FormAssociatedElement.cpp b/Libraries/LibWeb/HTML/FormAssociatedElement.cpp
index 00ad0fccae4..77482a22cd4 100644
--- a/Libraries/LibWeb/HTML/FormAssociatedElement.cpp
+++ b/Libraries/LibWeb/HTML/FormAssociatedElement.cpp
@@ -259,6 +259,24 @@ bool FormAssociatedElement::will_validate() const
return is_candidate_for_constraint_validation();
}
+// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-validationmessage
+Utf16String FormAssociatedElement::validation_message() const
+{
+ // 1. If this element is not a candidate for constraint validation or if this element satisfies its constraints,
+ // then return the empty string.
+ if (!is_candidate_for_constraint_validation() || satisfies_its_constraints())
+ return {};
+
+ // FIXME
+ // 2. Return a suitably localized message that the user agent would show the user if this were the only form
+ // control with a validity constraint problem. If the user agent would not actually show a textual message in
+ // such a situation (e.g., it would show a graphical cue instead), then return a suitably localized message that
+ // expresses (one or more of) the validity constraint(s) that the control does not satisfy. If the element is a
+ // candidate for constraint validation and is suffering from a custom error, then the custom validity error
+ // message should be present in the return value.
+ return "Invalid form"_utf16;
+}
+
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#check-validity-steps
bool FormAssociatedElement::check_validity_steps()
{
diff --git a/Libraries/LibWeb/HTML/FormAssociatedElement.h b/Libraries/LibWeb/HTML/FormAssociatedElement.h
index 16973c8a5c6..1d61b0c72fe 100644
--- a/Libraries/LibWeb/HTML/FormAssociatedElement.h
+++ b/Libraries/LibWeb/HTML/FormAssociatedElement.h
@@ -149,6 +149,9 @@ public:
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate
bool will_validate() const;
+ // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-validationmessage
+ Utf16String validation_message() const;
+
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-validity
GC::Ref validity() const;
diff --git a/Libraries/LibWeb/HTML/HTMLButtonElement.idl b/Libraries/LibWeb/HTML/HTMLButtonElement.idl
index b03dd132da5..cf3514310c6 100644
--- a/Libraries/LibWeb/HTML/HTMLButtonElement.idl
+++ b/Libraries/LibWeb/HTML/HTMLButtonElement.idl
@@ -30,7 +30,7 @@ interface HTMLButtonElement : HTMLElement {
readonly attribute boolean willValidate;
readonly attribute ValidityState validity;
- [FIXME] readonly attribute DOMString validationMessage;
+ readonly attribute Utf16DOMString validationMessage;
boolean checkValidity();
boolean reportValidity();
undefined setCustomValidity(DOMString error);
diff --git a/Libraries/LibWeb/HTML/HTMLFieldSetElement.idl b/Libraries/LibWeb/HTML/HTMLFieldSetElement.idl
index 594f07e1fbc..aab8b7d043b 100644
--- a/Libraries/LibWeb/HTML/HTMLFieldSetElement.idl
+++ b/Libraries/LibWeb/HTML/HTMLFieldSetElement.idl
@@ -16,7 +16,7 @@ interface HTMLFieldSetElement : HTMLElement {
readonly attribute boolean willValidate;
[FIXME, SameObject] readonly attribute ValidityState validity;
- [FIXME] readonly attribute DOMString validationMessage;
+ readonly attribute Utf16DOMString validationMessage;
boolean checkValidity();
boolean reportValidity();
undefined setCustomValidity(DOMString error);
diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.idl b/Libraries/LibWeb/HTML/HTMLInputElement.idl
index 6e4e9e040dc..c22c8a9d2ed 100644
--- a/Libraries/LibWeb/HTML/HTMLInputElement.idl
+++ b/Libraries/LibWeb/HTML/HTMLInputElement.idl
@@ -54,7 +54,7 @@ interface HTMLInputElement : HTMLElement {
readonly attribute boolean willValidate;
readonly attribute ValidityState validity;
- [FIXME] readonly attribute DOMString validationMessage;
+ readonly attribute Utf16DOMString validationMessage;
boolean checkValidity();
boolean reportValidity();
undefined setCustomValidity(DOMString error);
diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.idl b/Libraries/LibWeb/HTML/HTMLObjectElement.idl
index 1ce1876a4d3..12e48b883f1 100644
--- a/Libraries/LibWeb/HTML/HTMLObjectElement.idl
+++ b/Libraries/LibWeb/HTML/HTMLObjectElement.idl
@@ -20,7 +20,7 @@ interface HTMLObjectElement : HTMLElement {
readonly attribute boolean willValidate;
readonly attribute ValidityState validity;
- [FIXME] readonly attribute DOMString validationMessage;
+ readonly attribute Utf16DOMString validationMessage;
boolean checkValidity();
boolean reportValidity();
undefined setCustomValidity(DOMString error);
diff --git a/Libraries/LibWeb/HTML/HTMLOutputElement.idl b/Libraries/LibWeb/HTML/HTMLOutputElement.idl
index 1d49e96192d..d12d797582d 100644
--- a/Libraries/LibWeb/HTML/HTMLOutputElement.idl
+++ b/Libraries/LibWeb/HTML/HTMLOutputElement.idl
@@ -17,7 +17,7 @@ interface HTMLOutputElement : HTMLElement {
readonly attribute boolean willValidate;
readonly attribute ValidityState validity;
- [FIXME] readonly attribute DOMString validationMessage;
+ readonly attribute Utf16DOMString validationMessage;
boolean checkValidity();
boolean reportValidity();
undefined setCustomValidity(DOMString error);
diff --git a/Libraries/LibWeb/HTML/HTMLSelectElement.idl b/Libraries/LibWeb/HTML/HTMLSelectElement.idl
index ddaaefee40b..5e4cc34afdd 100644
--- a/Libraries/LibWeb/HTML/HTMLSelectElement.idl
+++ b/Libraries/LibWeb/HTML/HTMLSelectElement.idl
@@ -33,7 +33,7 @@ interface HTMLSelectElement : HTMLElement {
readonly attribute boolean willValidate;
readonly attribute ValidityState validity;
- [FIXME] readonly attribute DOMString validationMessage;
+ readonly attribute Utf16DOMString validationMessage;
boolean checkValidity();
boolean reportValidity();
undefined setCustomValidity(DOMString error);
diff --git a/Libraries/LibWeb/HTML/HTMLTextAreaElement.idl b/Libraries/LibWeb/HTML/HTMLTextAreaElement.idl
index d5056fc406a..5f602d63faf 100644
--- a/Libraries/LibWeb/HTML/HTMLTextAreaElement.idl
+++ b/Libraries/LibWeb/HTML/HTMLTextAreaElement.idl
@@ -28,7 +28,7 @@ interface HTMLTextAreaElement : HTMLElement {
readonly attribute boolean willValidate;
readonly attribute ValidityState validity;
- [FIXME] readonly attribute DOMString validationMessage;
+ readonly attribute Utf16DOMString validationMessage;
boolean checkValidity();
boolean reportValidity();
undefined setCustomValidity(DOMString error);
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/constraints/form-validation-validity-valueMissing.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/constraints/form-validation-validity-valueMissing.txt
index f6c81688994..4497e9d078d 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/constraints/form-validation-validity-valueMissing.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/constraints/form-validation-validity-valueMissing.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 78 tests
-77 Pass
-1 Fail
+78 Pass
Pass [INPUT in TEXT status] The required attribute is not set
Pass [INPUT in TEXT status] The value is not empty and required is true
Pass [INPUT in TEXT status] The value is empty and required is true
@@ -81,4 +80,4 @@ Pass [select] Selected the option with value equals to empty
Pass [textarea] The required attribute is not set
Pass [textarea] The value is not empty
Pass [textarea] The value is empty
-Fail validationMessage should return empty string when willValidate is false and valueMissing is true
\ No newline at end of file
+Pass validationMessage should return empty string when willValidate is false and valueMissing is true
\ No newline at end of file