diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
index 00e3a55113..3ab834a5b3 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
@@ -8,8 +8,14 @@
#include
#include
#include
+#include
+#include
#include
#include
+#include
+#include
+#include
+#include
#include
#include
#include
@@ -152,4 +158,40 @@ String HTMLFormElement::action() const
return value;
}
+static bool is_form_control(DOM::Element const& element)
+{
+ if (is(element)
+ || is(element)
+ || is(element)
+ || is(element)
+ || is(element)
+ || is(element)) {
+ return true;
+ }
+
+ if (is(element)
+ && !element.get_attribute(HTML::AttributeNames::type).equals_ignoring_case("image")) {
+ return true;
+ }
+
+ return false;
+}
+
+// https://html.spec.whatwg.org/multipage/forms.html#dom-form-elements
+NonnullRefPtr HTMLFormElement::elements() const
+{
+ // FIXME: This should return the same HTMLFormControlsCollection object every time,
+ // but that would cause a reference cycle since HTMLCollection refs the root.
+ return DOM::HTMLCollection::create(const_cast(*this), [this](Element const& element) {
+ return is_form_control(element);
+ });
+}
+
+// https://html.spec.whatwg.org/multipage/forms.html#dom-form-length
+unsigned HTMLFormElement::length() const
+{
+ // The length IDL attribute must return the number of nodes represented by the elements collection.
+ return elements()->length();
+}
+
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h
index 618b94756b..cd0a192a79 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h
@@ -29,6 +29,9 @@ public:
void add_associated_element(Badge, HTMLElement&);
void remove_associated_element(Badge, HTMLElement&);
+ NonnullRefPtr elements() const;
+ unsigned length() const;
+
private:
bool m_firing_submission_events { false };
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl
index b29a0f29a0..c2a443c534 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl
+++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl
@@ -1,3 +1,4 @@
+#import
#import
interface HTMLFormElement : HTMLElement {
@@ -9,4 +10,9 @@ interface HTMLFormElement : HTMLElement {
undefined submit();
+ // FIXME: Should be [SameObject] and a HTMLFormControlsCollection
+ readonly attribute HTMLCollection elements;
+
+ readonly attribute unsigned long length;
+
};