mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:07:35 +00:00
LibWeb: Expose HTMLSelectElement::options
Use the stub implementation of HTMLOptionsCollection to expose the `option` children of `select` elements. This fixes a JS error on openstreetmap.org, which occured when JQuery code tried to access `options.length`: https://github.com/jquery/jquery/blob/main/src/attributes/val.js#L121
This commit is contained in:
parent
624527f15e
commit
deef2911e9
3 changed files with 24 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibWeb/HTML/HTMLFormElement.h>
|
#include <LibWeb/HTML/HTMLFormElement.h>
|
||||||
|
#include <LibWeb/HTML/HTMLOptionElement.h>
|
||||||
#include <LibWeb/HTML/HTMLSelectElement.h>
|
#include <LibWeb/HTML/HTMLSelectElement.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
@ -19,4 +20,19 @@ HTMLSelectElement::~HTMLSelectElement()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options
|
||||||
|
RefPtr<HTMLOptionsCollection> const& HTMLSelectElement::options()
|
||||||
|
{
|
||||||
|
if (!m_options) {
|
||||||
|
m_options = HTMLOptionsCollection::create(*this, [](DOM::Element const& element) {
|
||||||
|
// https://html.spec.whatwg.org/multipage/form-elements.html#concept-select-option-list
|
||||||
|
// The list of options for a select element consists of all the option element children of
|
||||||
|
// the select element, and all the option element children of all the optgroup element children
|
||||||
|
// of the select element, in tree order.
|
||||||
|
return is<HTMLOptionElement>(element);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return m_options;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include <LibWeb/HTML/FormAssociatedElement.h>
|
#include <LibWeb/HTML/FormAssociatedElement.h>
|
||||||
#include <LibWeb/HTML/HTMLElement.h>
|
#include <LibWeb/HTML/HTMLElement.h>
|
||||||
|
#include <LibWeb/HTML/HTMLOptionsCollection.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
@ -20,6 +21,8 @@ public:
|
||||||
HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
|
HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
|
||||||
virtual ~HTMLSelectElement() override;
|
virtual ~HTMLSelectElement() override;
|
||||||
|
|
||||||
|
RefPtr<HTMLOptionsCollection> const& options();
|
||||||
|
|
||||||
// ^FormAssociatedElement
|
// ^FormAssociatedElement
|
||||||
// https://html.spec.whatwg.org/multipage/forms.html#category-listed
|
// https://html.spec.whatwg.org/multipage/forms.html#category-listed
|
||||||
virtual bool is_listed() const override { return true; }
|
virtual bool is_listed() const override { return true; }
|
||||||
|
@ -36,6 +39,9 @@ public:
|
||||||
// ^HTMLElement
|
// ^HTMLElement
|
||||||
// https://html.spec.whatwg.org/multipage/forms.html#category-label
|
// https://html.spec.whatwg.org/multipage/forms.html#category-label
|
||||||
virtual bool is_labelable() const override { return true; }
|
virtual bool is_labelable() const override { return true; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
RefPtr<HTMLOptionsCollection> m_options;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
#import <HTML/HTMLElement.idl>
|
#import <HTML/HTMLElement.idl>
|
||||||
|
#import <HTML/HTMLOptionsCollection.idl>
|
||||||
|
|
||||||
interface HTMLSelectElement : HTMLElement {
|
interface HTMLSelectElement : HTMLElement {
|
||||||
|
|
||||||
[Reflect] attribute boolean disabled;
|
[Reflect] attribute boolean disabled;
|
||||||
[Reflect] attribute boolean multiple;
|
[Reflect] attribute boolean multiple;
|
||||||
[Reflect] attribute boolean required;
|
[Reflect] attribute boolean required;
|
||||||
|
[SameObject] readonly attribute HTMLOptionsCollection options;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue