LibWeb: Check if input is disabled before submit event to form

This commit is contained in:
Felipe Muñoz Mazur 2025-01-14 13:16:25 -04:00 committed by Andrew Kaster
commit c2cc0d9cd0
Notes: github-actions[bot] 2025-02-05 21:47:22 +00:00
2 changed files with 17 additions and 6 deletions

View file

@ -6,6 +6,7 @@
* Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com> * Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org> * Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
* Copyright (c) 2024, Fernando Kiotheka <fer@k6a.dev> * Copyright (c) 2024, Fernando Kiotheka <fer@k6a.dev>
* Copyright (c) 2025, Felipe Muñoz Mazur <felipe.munoz.mazur@protonmail.com>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -376,8 +377,15 @@ WebIDL::ExceptionOr<void> HTMLInputElement::run_input_activation_behavior(DOM::E
auto change_event = DOM::Event::create(realm(), HTML::EventNames::change); auto change_event = DOM::Event::create(realm(), HTML::EventNames::change);
change_event->set_bubbles(true); change_event->set_bubbles(true);
dispatch_event(*change_event); dispatch_event(*change_event);
} else if (type_state() == TypeAttributeState::SubmitButton) { }
// https://html.spec.whatwg.org/multipage/input.html#submit-button-state-(type=submit)
else if (type_state() == TypeAttributeState::SubmitButton) {
GC::Ptr<HTMLFormElement> form; GC::Ptr<HTMLFormElement> form;
// The input element represents a button that, when activated, submits the form.
if (is_actually_disabled())
return {};
// 1. If the element does not have a form owner, then return. // 1. If the element does not have a form owner, then return.
if (!(form = this->form())) if (!(form = this->form()))
return {}; return {};
@ -418,6 +426,10 @@ WebIDL::ExceptionOr<void> HTMLInputElement::run_input_activation_behavior(DOM::E
} }
// https://html.spec.whatwg.org/multipage/input.html#reset-button-state-(type=reset) // https://html.spec.whatwg.org/multipage/input.html#reset-button-state-(type=reset)
else if (type_state() == TypeAttributeState::ResetButton) { else if (type_state() == TypeAttributeState::ResetButton) {
// The input element represents a button that, when activated, resets the form.
if (is_actually_disabled())
return {};
// 1. If the element does not have a form owner, then return. // 1. If the element does not have a form owner, then return.
auto* form = this->form(); auto* form = this->form();
if (!form) if (!form)

View file

@ -2,8 +2,7 @@ Harness status: OK
Found 33 tests Found 33 tests
30 Pass 33 Pass
3 Fail
Pass basic with click() Pass basic with click()
Pass basic with dispatchEvent() Pass basic with dispatchEvent()
Pass basic with wrong event class Pass basic with wrong event class
@ -34,6 +33,6 @@ Pass disabling checkbox in onclick listener shouldn't suppress onchange
Pass disabling radio in onclick listener shouldn't suppress oninput Pass disabling radio in onclick listener shouldn't suppress oninput
Pass disabling radio in onclick listener shouldn't suppress onchange Pass disabling radio in onclick listener shouldn't suppress onchange
Pass disconnected form should not submit Pass disconnected form should not submit
Fail disabled submit button should not activate Pass disabled submit button should not activate
Fail submit button should not activate if the event listener disables it Pass submit button should not activate if the event listener disables it
Fail submit button that morphed from checkbox should not activate Pass submit button that morphed from checkbox should not activate