ladybird/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp
Simon Wanner deef2911e9 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
2022-03-16 14:25:09 +01:00

38 lines
1.2 KiB
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/HTML/HTMLFormElement.h>
#include <LibWeb/HTML/HTMLOptionElement.h>
#include <LibWeb/HTML/HTMLSelectElement.h>
namespace Web::HTML {
HTMLSelectElement::HTMLSelectElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: FormAssociatedElement(document, move(qualified_name))
{
}
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;
}
}