diff --git a/Tests/LibWeb/Text/expected/html-form-controls-collection.txt b/Tests/LibWeb/Text/expected/html-form-controls-collection.txt index 1fcbce521a..7440fc4ae8 100644 --- a/Tests/LibWeb/Text/expected/html-form-controls-collection.txt +++ b/Tests/LibWeb/Text/expected/html-form-controls-collection.txt @@ -1,8 +1,87 @@ HTMLFormControlsCollection +2 +------------------- +form.namedItem("formcontrol") +------------------- RadioNodeList 2 button text -null +------------------- +form.namedItem("one") +------------------- HTMLInputElement +formcontrol +button +------------------- +form.namedItem("two") +------------------- +HTMLInputElement +formcontrol text +------------------- +form.namedItem("nomatch") +------------------- +null +------------------- +form["formcontrol"] +------------------- +RadioNodeList +2 +button +text +------------------- +form["one"] +------------------- +HTMLInputElement +formcontrol +button +------------------- +form["two"] +------------------- +HTMLInputElement +formcontrol +text +------------------- +form["nomatch"] +------------------- +undefined +------------------- +form.formcontrol +------------------- +RadioNodeList +2 +button +text +------------------- +form.one +------------------- +HTMLInputElement +formcontrol +button +------------------- +form.two +------------------- +HTMLInputElement +formcontrol +text +------------------- +form.nomatch +------------------- +undefined +------------------- +form[0] +------------------- +HTMLInputElement +formcontrol +button +------------------- +form[1] +------------------- +HTMLInputElement +formcontrol +text +------------------- +form[2] +------------------- +undefined diff --git a/Tests/LibWeb/Text/input/html-form-controls-collection.html b/Tests/LibWeb/Text/input/html-form-controls-collection.html index 8e28c16c96..27d3fb0867 100644 --- a/Tests/LibWeb/Text/input/html-form-controls-collection.html +++ b/Tests/LibWeb/Text/input/html-form-controls-collection.html @@ -1,24 +1,57 @@
- - + +
diff --git a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp b/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp index 42e4f2cf8e..afac7db0c6 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp +++ b/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp @@ -77,4 +77,11 @@ Variant> HTMLFormControlsCollection:: })); } +WebIDL::ExceptionOr HTMLFormControlsCollection::named_item_value(FlyString const& name) const +{ + return named_item_or_radio_node_list(name).visit( + [](Empty) -> JS::Value { return JS::js_undefined(); }, + [](auto const& value) -> JS::Value { return value; }); +} + } diff --git a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.h b/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.h index aba67236f7..e20ee229c0 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.h +++ b/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.h @@ -25,6 +25,8 @@ public: protected: virtual void initialize(JS::Realm&) override; + virtual WebIDL::ExceptionOr named_item_value(FlyString const& name) const final; + private: HTMLFormControlsCollection(ParentNode& root, Scope, Function filter); };