diff --git a/Libraries/LibWeb/HTML/HTMLButtonElement.cpp b/Libraries/LibWeb/HTML/HTMLButtonElement.cpp index e4fbcc9a7c..f5bfe43193 100644 --- a/Libraries/LibWeb/HTML/HTMLButtonElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLButtonElement.cpp @@ -156,6 +156,13 @@ void HTMLButtonElement::activation_behavior(DOM::Event const& event) PopoverInvokerElement::popover_target_activation_behaviour(*this, as(*event.target())); } +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate +bool HTMLButtonElement::will_validate() +{ + // The willValidate attribute's getter must return true, if this element is a candidate for constraint validation + return is_candidate_for_constraint_validation(); +} + bool HTMLButtonElement::is_focusable() const { return enabled(); diff --git a/Libraries/LibWeb/HTML/HTMLButtonElement.h b/Libraries/LibWeb/HTML/HTMLButtonElement.h index 3a239914a8..831256ac81 100644 --- a/Libraries/LibWeb/HTML/HTMLButtonElement.h +++ b/Libraries/LibWeb/HTML/HTMLButtonElement.h @@ -44,6 +44,8 @@ public: virtual void form_associated_element_attribute_changed(FlyString const& name, Optional const& value, Optional const& namespace_) override; + bool will_validate(); + // ^EventTarget // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-button-element // https://html.spec.whatwg.org/multipage/interaction.html#focusable-area diff --git a/Libraries/LibWeb/HTML/HTMLButtonElement.idl b/Libraries/LibWeb/HTML/HTMLButtonElement.idl index 65e6fba987..7a691f0733 100644 --- a/Libraries/LibWeb/HTML/HTMLButtonElement.idl +++ b/Libraries/LibWeb/HTML/HTMLButtonElement.idl @@ -26,7 +26,7 @@ interface HTMLButtonElement : HTMLElement { [CEReactions, ImplementedAs=type_for_bindings, Enumerated=ButtonTypeState] attribute DOMString type; [CEReactions, Reflect] attribute DOMString value; - [FIXME] readonly attribute boolean willValidate; + readonly attribute boolean willValidate; readonly attribute ValidityState validity; [FIXME] readonly attribute DOMString validationMessage; [FIXME] boolean checkValidity(); diff --git a/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp b/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp index 57e07f7b69..38a72357f0 100644 --- a/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp @@ -88,4 +88,15 @@ GC::Ptr HTMLFieldSetElement::create_layout_node(GC::Ref(document(), *this, style); } +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate +bool HTMLFieldSetElement::will_validate() +{ + // The willValidate attribute's getter must return true, if this element is a candidate for constraint validation, + // and false otherwise (i.e., false if any conditions are barring it from constraint validation). + // A submittable element is a candidate for constraint validation + // https://html.spec.whatwg.org/multipage/forms.html#category-submit + // Submittable elements: button, input, select, textarea, form-associated custom elements [but not fieldset] + return false; +} + } diff --git a/Libraries/LibWeb/HTML/HTMLFieldSetElement.h b/Libraries/LibWeb/HTML/HTMLFieldSetElement.h index de7d57dcf4..fa60703acf 100644 --- a/Libraries/LibWeb/HTML/HTMLFieldSetElement.h +++ b/Libraries/LibWeb/HTML/HTMLFieldSetElement.h @@ -42,6 +42,8 @@ public: virtual Optional default_role() const override { return ARIA::Role::group; } + static bool will_validate(); + virtual GC::Ptr create_layout_node(GC::Ref) override; Layout::FieldSetBox* layout_node(); Layout::FieldSetBox const* layout_node() const; diff --git a/Libraries/LibWeb/HTML/HTMLFieldSetElement.idl b/Libraries/LibWeb/HTML/HTMLFieldSetElement.idl index 494619e576..7bdf58c0f5 100644 --- a/Libraries/LibWeb/HTML/HTMLFieldSetElement.idl +++ b/Libraries/LibWeb/HTML/HTMLFieldSetElement.idl @@ -14,7 +14,7 @@ interface HTMLFieldSetElement : HTMLElement { [SameObject] readonly attribute HTMLCollection elements; - [FIXME] readonly attribute boolean willValidate; + readonly attribute boolean willValidate; [FIXME, SameObject] readonly attribute ValidityState validity; [FIXME] readonly attribute DOMString validationMessage; [FIXME] boolean checkValidity(); diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp index ebd935764f..e934a86565 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -2523,6 +2523,13 @@ WebIDL::ExceptionOr HTMLInputElement::step_up_or_down(bool is_down, WebIDL return {}; } +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate +bool HTMLInputElement::will_validate() +{ + // The willValidate attribute's getter must return true, if this element is a candidate for constraint validation + return is_candidate_for_constraint_validation(); +} + // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-checkvalidity WebIDL::ExceptionOr HTMLInputElement::check_validity() { diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.h b/Libraries/LibWeb/HTML/HTMLInputElement.h index 9e0993aae9..f67d47f647 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -149,6 +149,7 @@ public: WebIDL::ExceptionOr step_up(WebIDL::Long n = 1); WebIDL::ExceptionOr step_down(WebIDL::Long n = 1); + bool will_validate(); WebIDL::ExceptionOr check_validity(); WebIDL::ExceptionOr report_validity(); diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.idl b/Libraries/LibWeb/HTML/HTMLInputElement.idl index c308e5f36b..fd8df9cf98 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.idl +++ b/Libraries/LibWeb/HTML/HTMLInputElement.idl @@ -51,7 +51,7 @@ interface HTMLInputElement : HTMLElement { undefined stepUp(optional long n = 1); undefined stepDown(optional long n = 1); - [FIXME] readonly attribute boolean willValidate; + readonly attribute boolean willValidate; readonly attribute ValidityState validity; [FIXME] readonly attribute DOMString validationMessage; boolean checkValidity(); diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp index 5d5d1e25ea..38937d316e 100644 --- a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp @@ -79,6 +79,17 @@ void HTMLObjectElement::visit_edges(Cell::Visitor& visitor) visitor.visit(m_document_observer); } +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate +bool HTMLObjectElement::will_validate() +{ + // The willValidate attribute's getter must return true, if this element is a candidate for constraint validation, + // and false otherwise (i.e., false if any conditions are barring it from constraint validation). + // A submittable element is a candidate for constraint validation + // https://html.spec.whatwg.org/multipage/forms.html#category-submit + // Submittable elements: button, input, select, textarea, form-associated custom elements [but not object] + return false; +} + void HTMLObjectElement::form_associated_element_attribute_changed(FlyString const& name, Optional const&, Optional const&) { // https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-object-element diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.h b/Libraries/LibWeb/HTML/HTMLObjectElement.h index c165a10a70..ccecc5e1b3 100644 --- a/Libraries/LibWeb/HTML/HTMLObjectElement.h +++ b/Libraries/LibWeb/HTML/HTMLObjectElement.h @@ -47,6 +47,8 @@ public: virtual void visit_edges(Cell::Visitor&) override; + static bool will_validate(); + private: HTMLObjectElement(DOM::Document&, DOM::QualifiedName); diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.idl b/Libraries/LibWeb/HTML/HTMLObjectElement.idl index dc10637152..c91494d548 100644 --- a/Libraries/LibWeb/HTML/HTMLObjectElement.idl +++ b/Libraries/LibWeb/HTML/HTMLObjectElement.idl @@ -18,7 +18,7 @@ interface HTMLObjectElement : HTMLElement { readonly attribute WindowProxy? contentWindow; Document? getSVGDocument(); - [FIXME] readonly attribute boolean willValidate; + readonly attribute boolean willValidate; readonly attribute ValidityState validity; [FIXME] readonly attribute DOMString validationMessage; [FIXME] boolean checkValidity(); diff --git a/Libraries/LibWeb/HTML/HTMLOutputElement.cpp b/Libraries/LibWeb/HTML/HTMLOutputElement.cpp index dae7cfa3cb..2d22682370 100644 --- a/Libraries/LibWeb/HTML/HTMLOutputElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLOutputElement.cpp @@ -110,4 +110,15 @@ void HTMLOutputElement::clear_algorithm() string_replace_all({}); } +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate +bool HTMLOutputElement::will_validate() +{ + // The willValidate attribute's getter must return true, if this element is a candidate for constraint validation, + // and false otherwise (i.e., false if any conditions are barring it from constraint validation). + // A submittable element is a candidate for constraint validation + // https://html.spec.whatwg.org/multipage/forms.html#category-submit + // Submittable elements: button, input, select, textarea, form-associated custom elements [but not output] + return false; +} + } diff --git a/Libraries/LibWeb/HTML/HTMLOutputElement.h b/Libraries/LibWeb/HTML/HTMLOutputElement.h index 6c066dd78e..9c2f7834e6 100644 --- a/Libraries/LibWeb/HTML/HTMLOutputElement.h +++ b/Libraries/LibWeb/HTML/HTMLOutputElement.h @@ -57,6 +57,8 @@ public: // https://www.w3.org/TR/html-aria/#el-output virtual Optional default_role() const override { return ARIA::Role::status; } + static bool will_validate(); + private: HTMLOutputElement(DOM::Document&, DOM::QualifiedName); diff --git a/Libraries/LibWeb/HTML/HTMLOutputElement.idl b/Libraries/LibWeb/HTML/HTMLOutputElement.idl index fd03c3b2a3..f96e448018 100644 --- a/Libraries/LibWeb/HTML/HTMLOutputElement.idl +++ b/Libraries/LibWeb/HTML/HTMLOutputElement.idl @@ -15,7 +15,7 @@ interface HTMLOutputElement : HTMLElement { [CEReactions] attribute DOMString defaultValue; [CEReactions] attribute DOMString value; - [FIXME] readonly attribute boolean willValidate; + readonly attribute boolean willValidate; readonly attribute ValidityState validity; [FIXME] readonly attribute DOMString validationMessage; [FIXME] boolean checkValidity(); diff --git a/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index 8dcf2f8637..b8549d06c4 100644 --- a/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -695,6 +695,13 @@ void HTMLSelectElement::update_selectedness() update_inner_text_element(); } +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate +bool HTMLSelectElement::will_validate() +{ + // The willValidate attribute's getter must return true, if this element is a candidate for constraint validation + return is_candidate_for_constraint_validation(); +} + bool HTMLSelectElement::is_focusable() const { return enabled(); diff --git a/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Libraries/LibWeb/HTML/HTMLSelectElement.h index ce1884c1c3..4cb72b20d6 100644 --- a/Libraries/LibWeb/HTML/HTMLSelectElement.h +++ b/Libraries/LibWeb/HTML/HTMLSelectElement.h @@ -58,6 +58,8 @@ public: Vector> list_of_options() const; + bool will_validate(); + // ^EventTarget // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-select-element // https://html.spec.whatwg.org/multipage/interaction.html#focusable-area diff --git a/Libraries/LibWeb/HTML/HTMLSelectElement.idl b/Libraries/LibWeb/HTML/HTMLSelectElement.idl index f335665ca3..dd42e47748 100644 --- a/Libraries/LibWeb/HTML/HTMLSelectElement.idl +++ b/Libraries/LibWeb/HTML/HTMLSelectElement.idl @@ -31,7 +31,7 @@ interface HTMLSelectElement : HTMLElement { attribute long selectedIndex; attribute DOMString value; - [FIXME] readonly attribute boolean willValidate; + readonly attribute boolean willValidate; readonly attribute ValidityState validity; [FIXME] readonly attribute DOMString validationMessage; [FIXME] boolean checkValidity(); diff --git a/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp b/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp index 12ccbe92ec..cc35f7c00a 100644 --- a/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp @@ -237,6 +237,13 @@ u32 HTMLTextAreaElement::text_length() const return AK::utf16_code_unit_length_from_utf8(api_value()); } +// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-willvalidate +bool HTMLTextAreaElement::will_validate() +{ + // The willValidate attribute's getter must return true, if this element is a candidate for constraint validation + return is_candidate_for_constraint_validation(); +} + // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-checkvalidity bool HTMLTextAreaElement::check_validity() { diff --git a/Libraries/LibWeb/HTML/HTMLTextAreaElement.h b/Libraries/LibWeb/HTML/HTMLTextAreaElement.h index 5ebafec801..430841df70 100644 --- a/Libraries/LibWeb/HTML/HTMLTextAreaElement.h +++ b/Libraries/LibWeb/HTML/HTMLTextAreaElement.h @@ -95,6 +95,7 @@ public: u32 text_length() const; + bool will_validate(); bool check_validity(); bool report_validity(); diff --git a/Libraries/LibWeb/HTML/HTMLTextAreaElement.idl b/Libraries/LibWeb/HTML/HTMLTextAreaElement.idl index eec164b647..ba3ac128ee 100644 --- a/Libraries/LibWeb/HTML/HTMLTextAreaElement.idl +++ b/Libraries/LibWeb/HTML/HTMLTextAreaElement.idl @@ -26,7 +26,7 @@ interface HTMLTextAreaElement : HTMLElement { [LegacyNullToEmptyString] attribute DOMString value; readonly attribute unsigned long textLength; - [FIXME] readonly attribute boolean willValidate; + readonly attribute boolean willValidate; readonly attribute ValidityState validity; [FIXME] readonly attribute DOMString validationMessage; boolean checkValidity(); diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/constraints/form-validation-willValidate.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/constraints/form-validation-willValidate.txt new file mode 100644 index 0000000000..e9eb0b237b --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/constraints/form-validation-willValidate.txt @@ -0,0 +1,78 @@ +Harness status: OK + +Found 73 tests + +73 Pass +Pass [INPUT in HIDDEN status] Must be barred from the constraint validation +Pass [INPUT in BUTTON status] Must be barred from the constraint validation +Pass [INPUT in RESET status] Must be barred from the constraint validation +Pass [BUTTON in BUTTON status] Must be barred from the constraint validation +Pass [BUTTON in RESET status] Must be barred from the constraint validation +Pass [fieldset] The willValidate attribute must be false since FIELDSET is not a submittable element +Pass [output] The willValidate attribute must be false since OUTPUT is not a submittable element +Pass [object] Must be barred from the constraint validation +Pass [INPUT in TEXT status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in TEXT status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in TEXT status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in TEXT status] The willValidate attribute must be false if it has a datalist ancestor +Pass [INPUT in SEARCH status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in SEARCH status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in SEARCH status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in SEARCH status] The willValidate attribute must be false if it has a datalist ancestor +Pass [INPUT in TEL status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in TEL status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in TEL status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in TEL status] The willValidate attribute must be false if it has a datalist ancestor +Pass [INPUT in URL status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in URL status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in URL status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in URL status] The willValidate attribute must be false if it has a datalist ancestor +Pass [INPUT in EMAIL status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in EMAIL status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in EMAIL status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in EMAIL status] The willValidate attribute must be false if it has a datalist ancestor +Pass [INPUT in PASSWORD status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in PASSWORD status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in PASSWORD status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in PASSWORD status] The willValidate attribute must be false if it has a datalist ancestor +Pass [INPUT in DATETIME-LOCAL status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in DATETIME-LOCAL status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in DATETIME-LOCAL status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in DATETIME-LOCAL status] The willValidate attribute must be false if it has a datalist ancestor +Pass [INPUT in DATE status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in DATE status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in DATE status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in DATE status] The willValidate attribute must be false if it has a datalist ancestor +Pass [INPUT in MONTH status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in MONTH status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in MONTH status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in MONTH status] The willValidate attribute must be false if it has a datalist ancestor +Pass [INPUT in WEEK status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in WEEK status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in WEEK status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in WEEK status] The willValidate attribute must be false if it has a datalist ancestor +Pass [INPUT in TIME status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in TIME status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in TIME status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in TIME status] The willValidate attribute must be false if it has a datalist ancestor +Pass [INPUT in COLOR status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in COLOR status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in COLOR status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in COLOR status] The willValidate attribute must be false if it has a datalist ancestor +Pass [INPUT in FILE status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in FILE status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in FILE status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in FILE status] The willValidate attribute must be false if it has a datalist ancestor +Pass [INPUT in SUBMIT status] Must be barred from the constraint validation if it is disabled +Pass [INPUT in SUBMIT status] The willValidate attribute must be true if an element is mutable +Pass [INPUT in SUBMIT status] Must be barred from the constraint validation if it is readonly +Pass [INPUT in SUBMIT status] The willValidate attribute must be false if it has a datalist ancestor +Pass [BUTTON in SUBMIT status] Must be barred from the constraint validation +Pass [BUTTON in SUBMIT status] The willValidate attribute must be true if an element is mutable +Pass [BUTTON in SUBMIT status] The willValidate attribute must be false if it has a datalist ancestor +Pass [select] Must be barred from the constraint validation +Pass [select] The willValidate attribute must be true if an element is mutable +Pass [select] The willValidate attribute must be false if it has a datalist ancestor +Pass [textarea] Must be barred from the constraint validation +Pass [textarea] The willValidate attribute must be true if an element is mutable +Pass [textarea] The willValidate attribute must be false if it has a datalist ancestor \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-select-element/select-willvalidate-readonly-attribute.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-select-element/select-willvalidate-readonly-attribute.txt index 100fb28078..b5c2a3c39f 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-select-element/select-willvalidate-readonly-attribute.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-select-element/select-willvalidate-readonly-attribute.txt @@ -2,5 +2,5 @@ Harness status: OK Found 1 tests -1 Fail -Fail Select element with "readonly" attribute shouldn't be barred from constraint validation \ No newline at end of file +1 Pass +Pass Select element with "readonly" attribute shouldn't be barred from constraint validation \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/constraints/form-validation-willValidate.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/constraints/form-validation-willValidate.html new file mode 100644 index 0000000000..9442faea78 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/constraints/form-validation-willValidate.html @@ -0,0 +1,96 @@ + + +The constraint validation API Test: element.willValidate + + + + + + +
+