From 0f374afc8f6f792fdfa076125d2d6ae58f8db0c0 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 26 Aug 2023 13:28:58 +1200 Subject: [PATCH] LibWeb: Handle radio/checkbox default-or-on value attribute state If the value attribute is missing, these input elements should be returning 'on' as their value in their IDL. --- Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 474bcafc58..7bfc8d7aab 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -2,6 +2,7 @@ * Copyright (c) 2018-2023, Andreas Kling * Copyright (c) 2022, Adam Hodgen * Copyright (c) 2022, Andrew Kaster + * Copyright (c) 2023, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ @@ -310,6 +311,12 @@ DeprecatedString HTMLInputElement::value() const return DeprecatedString::empty(); } + // https://html.spec.whatwg.org/multipage/input.html#dom-input-value-default-on + if (type_state() == TypeAttributeState::Checkbox || type_state() == TypeAttributeState::RadioButton) { + // On getting, if the element has a value content attribute, return that attribute's value; otherwise, return the string "on". + return has_attribute(AttributeNames::value) ? get_attribute(AttributeNames::value) : "on"; + } + // https://html.spec.whatwg.org/multipage/input.html#dom-input-value-value // Return the current value of the element. return m_value;