Skip to content

Lightpanda: the headless browser designed for AI and automation

form: check the element is disable on click

Pierre Tachoire5c85f763e49a
diff --git a/src/browser/frame/user_input.zig b/src/browser/frame/user_input.zig
index c5bf625c7..5fc659a99 100644
--- a/src/browser/frame/user_input.zig
+++ b/src/browser/frame/user_input.zig
@@ -737,13 +737,22 @@ pub fn handleClick(frame: *Frame, target: *Node, event_target: *Node) !void {
// image button submits its form. The form-data set already gets the
// submitter's coordinate fields appended via FormData.collectForm
// (see src/browser/webapi/net/FormData.zig).
+ // A disabled submit button has no activation behavior; isDisabled
+ // also covers an ancestor <fieldset disabled>, which a synthetic
+ // dispatchEvent click does not otherwise check.
if (input._input_type == .submit or input._input_type == .image) {
+ if (element.isDisabled()) {
+ return;
+ }
return frame.submitForm(element, input.getForm(frame), .{});
}
},
.button => {
const button = html_element.subtype(Element.Html.Button);
if (std.mem.eql(u8, button.getType(), "submit")) {
+ if (element.isDisabled()) {
+ return;
+ }
return frame.submitForm(element, button.getForm(frame), .{});
}
},
diff --git a/src/browser/tests/element/html/button.html b/src/browser/tests/element/html/button.html
index ac9953423..7860ab86f 100644
--- a/src/browser/tests/element/html/button.html
+++ b/src/browser/tests/element/html/button.html
@@ -285,3 +285,36 @@
testing.expectEqual(1, clicks);
}
</script>
+
+<form id="fieldset_form">
+ <fieldset disabled>
+ <legend><button id="fs_legend_btn">legend</button></legend>
+ <button id="fs_btn">go</button>
+ <input id="fs_input" type="submit">
+ <input id="fs_image" type="image">
+ </fieldset>
+ <button id="fs_disabled_btn" disabled>off</button>
+ <button id="fs_enabled_btn">on</button>
+</form>
+
+<script id="synthetic_click_disabled_submitter">
+ {
+ // A disabled submit button has no activation behavior, so a synthetic
+ // click must not submit; an ancestor <fieldset disabled> disables it too,
+ // except inside the fieldset's first <legend>.
+ const submitted = []
+ const form = $('#fieldset_form')
+ form.addEventListener('submit', (e) => {
+ e.preventDefault()
+ submitted.push(e.submitter.id)
+ })
+ const click = (id) => $('#' + id).dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }))
+
+ for (const id of ['fs_btn', 'fs_input', 'fs_image', 'fs_disabled_btn']) click(id)
+ testing.expectEqual([], submitted)
+
+ click('fs_legend_btn')
+ click('fs_enabled_btn')
+ testing.expectEqual(['fs_legend_btn', 'fs_enabled_btn'], submitted)
+ }
+</script>