LibWeb: Implement validation_message for form associated elements

It wins us a quick WPT test as well as implement a bunch of IDL methods.
This commit is contained in:
Tete17 2025-08-29 18:02:59 +02:00 committed by Tim Ledbetter
parent 8ab568bc76
commit 70c3f203ef
Notes: github-actions[bot] 2025-08-29 18:28:51 +00:00
10 changed files with 30 additions and 10 deletions

View file

@ -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()
{

View file

@ -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<ValidityState const> validity() const;

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);