mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
LibWeb: Do not assume grouped radio buttons have the same parent
For example: <div> <input type=radio name=group value=item1 /> </div> <div> <input type=radio name=group value=item2 /> </div> Is a valid DOM and clicking on of these radio buttons should uncheck the other.
This commit is contained in:
parent
7648f6aa7b
commit
4f9e9c0715
Notes:
sideshowbarker
2024-07-18 20:50:05 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/4f9e9c07150 Pull-request: https://github.com/SerenityOS/serenity/pull/6105
@ -27,6 +27,7 @@
|
||||
#include <LibGUI/Event.h>
|
||||
#include <LibGfx/Painter.h>
|
||||
#include <LibGfx/StylePainter.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/Layout/RadioButton.h>
|
||||
#include <LibWeb/Page/Frame.h>
|
||||
|
||||
@ -105,20 +106,12 @@ void RadioButton::set_checked_within_group()
|
||||
return;
|
||||
|
||||
dom_node().set_checked(true);
|
||||
|
||||
if (!parent())
|
||||
return;
|
||||
|
||||
String name = dom_node().name();
|
||||
|
||||
parent()->for_each_child_of_type<RadioButton>([&](auto& child) {
|
||||
if (&child == this)
|
||||
return;
|
||||
if (!child.dom_node().checked())
|
||||
return;
|
||||
|
||||
if (child.dom_node().name() == name)
|
||||
child.dom_node().set_checked(false);
|
||||
document().for_each_in_subtree_of_type<HTML::HTMLInputElement>([&](auto& element) {
|
||||
if (element.checked() && (element.layout_node() != this) && (element.name() == name))
|
||||
element.set_checked(false);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user