mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:18:12 +00:00
LibWeb: Return a HTMLFormControlsCollection from HTMLFormElement element
Instead of a HTMLCollection
This commit is contained in:
parent
27dd2a40ad
commit
9cf5b67162
5 changed files with 39 additions and 7 deletions
|
@ -0,0 +1,8 @@
|
||||||
|
HTMLFormControlsCollection
|
||||||
|
RadioNodeList
|
||||||
|
2
|
||||||
|
button
|
||||||
|
text
|
||||||
|
null
|
||||||
|
HTMLInputElement
|
||||||
|
text
|
24
Tests/LibWeb/Text/input/html-form-controls-collection.html
Normal file
24
Tests/LibWeb/Text/input/html-form-controls-collection.html
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<form>
|
||||||
|
<input name="one" id="my-form-control" type="button" />
|
||||||
|
<input name="two" id="my-form-control" type="text" />
|
||||||
|
</form>
|
||||||
|
<script src="include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const formElements = document.forms[0].elements;
|
||||||
|
const radioNodeList = formElements.namedItem("my-form-control");
|
||||||
|
|
||||||
|
println(formElements.constructor.name);
|
||||||
|
println(radioNodeList.constructor.name);
|
||||||
|
println(radioNodeList.length);
|
||||||
|
println(radioNodeList[0].type);
|
||||||
|
println(radioNodeList[1].type);
|
||||||
|
|
||||||
|
const nonMatching = formElements.namedItem("no match");
|
||||||
|
println(nonMatching);
|
||||||
|
|
||||||
|
const singleElement = formElements.namedItem("two");
|
||||||
|
println(singleElement.constructor.name);
|
||||||
|
println(singleElement.type);
|
||||||
|
})
|
||||||
|
</script>
|
|
@ -11,6 +11,7 @@
|
||||||
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/DOM/Event.h>
|
#include <LibWeb/DOM/Event.h>
|
||||||
|
#include <LibWeb/DOM/HTMLFormControlsCollection.h>
|
||||||
#include <LibWeb/HTML/BrowsingContext.h>
|
#include <LibWeb/HTML/BrowsingContext.h>
|
||||||
#include <LibWeb/HTML/EventNames.h>
|
#include <LibWeb/HTML/EventNames.h>
|
||||||
#include <LibWeb/HTML/FormControlInfrastructure.h>
|
#include <LibWeb/HTML/FormControlInfrastructure.h>
|
||||||
|
@ -406,10 +407,10 @@ static bool is_form_control(DOM::Element const& element)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-elements
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-elements
|
||||||
JS::NonnullGCPtr<DOM::HTMLCollection> HTMLFormElement::elements() const
|
JS::NonnullGCPtr<DOM::HTMLFormControlsCollection> HTMLFormElement::elements() const
|
||||||
{
|
{
|
||||||
if (!m_elements) {
|
if (!m_elements) {
|
||||||
m_elements = DOM::HTMLCollection::create(const_cast<HTMLFormElement&>(*this), DOM::HTMLCollection::Scope::Descendants, [](Element const& element) {
|
m_elements = DOM::HTMLFormControlsCollection::create(const_cast<HTMLFormElement&>(*this), DOM::HTMLCollection::Scope::Descendants, [](Element const& element) {
|
||||||
return is_form_control(element);
|
return is_form_control(element);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ public:
|
||||||
|
|
||||||
ErrorOr<Vector<JS::NonnullGCPtr<DOM::Element>>> get_submittable_elements();
|
ErrorOr<Vector<JS::NonnullGCPtr<DOM::Element>>> get_submittable_elements();
|
||||||
|
|
||||||
JS::NonnullGCPtr<DOM::HTMLCollection> elements() const;
|
JS::NonnullGCPtr<DOM::HTMLFormControlsCollection> elements() const;
|
||||||
unsigned length() const;
|
unsigned length() const;
|
||||||
|
|
||||||
WebIDL::ExceptionOr<bool> check_validity();
|
WebIDL::ExceptionOr<bool> check_validity();
|
||||||
|
@ -110,7 +110,7 @@ private:
|
||||||
|
|
||||||
Vector<JS::GCPtr<HTMLElement>> m_associated_elements;
|
Vector<JS::GCPtr<HTMLElement>> m_associated_elements;
|
||||||
|
|
||||||
JS::GCPtr<DOM::HTMLCollection> mutable m_elements;
|
JS::GCPtr<DOM::HTMLFormControlsCollection> mutable m_elements;
|
||||||
|
|
||||||
bool m_constructing_entry_list { false };
|
bool m_constructing_entry_list { false };
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#import <DOM/HTMLCollection.idl>
|
#import <DOM/HTMLFormControlsCollection.idl>
|
||||||
#import <HTML/HTMLElement.idl>
|
#import <HTML/HTMLElement.idl>
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/semantics.html#htmlformelement
|
// https://html.spec.whatwg.org/multipage/semantics.html#htmlformelement
|
||||||
|
@ -20,8 +20,7 @@ interface HTMLFormElement : HTMLElement {
|
||||||
boolean checkValidity();
|
boolean checkValidity();
|
||||||
boolean reportValidity();
|
boolean reportValidity();
|
||||||
|
|
||||||
// FIXME: Should be a HTMLFormControlsCollection
|
[SameObject] readonly attribute HTMLFormControlsCollection elements;
|
||||||
[SameObject] readonly attribute HTMLCollection elements;
|
|
||||||
|
|
||||||
readonly attribute unsigned long length;
|
readonly attribute unsigned long length;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue