From 191c87f1cd09c15f556291fff8797730371cdf5d Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 26 Aug 2023 13:33:51 +1200 Subject: [PATCH] LibWeb: Handle 'default' value state for input elements For buttons and the hidden state the value IDL call must return the empty string if there is no value, and the elements value attribute otherwise. --- Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 7bfc8d7aab..ac514b3730 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -317,6 +317,16 @@ DeprecatedString HTMLInputElement::value() const return has_attribute(AttributeNames::value) ? get_attribute(AttributeNames::value) : "on"; } + // https://html.spec.whatwg.org/multipage/input.html#dom-input-value-default + if (type_state() == TypeAttributeState::Hidden + || type_state() == TypeAttributeState::SubmitButton + || type_state() == TypeAttributeState::ImageButton + || type_state() == TypeAttributeState::ResetButton + || type_state() == TypeAttributeState::Button) { + // On getting, if the element has a value content attribute, return that attribute's value; otherwise, return the empty string. + return has_attribute(AttributeNames::value) ? get_attribute(AttributeNames::value) : DeprecatedString::empty(); + } + // https://html.spec.whatwg.org/multipage/input.html#dom-input-value-value // Return the current value of the element. return m_value;