Merge pull request #2253 from navidemad/fix-requestsubmit-default-submitter

Fix SubmitEvent.submitter for requestSubmit() with no argument
This commit is contained in:
Karl Seguin
2026-04-27 12:20:36 +08:00
committed by GitHub
2 changed files with 13 additions and 4 deletions

View File

@@ -3701,7 +3701,15 @@ pub fn submitForm(self: *Frame, submitter_: ?*Element, form_: ?*Element.Html.For
};
if (submit_opts.fire_event) {
const submitter_html: ?*HtmlElement = if (submitter_) |s| s.is(HtmlElement) else null;
// Per HTML spec "submit a form element" algorithm: SubmitEvent.submitter
// must be null when the submitter is the form itself, which is what
// Form.requestSubmit() passes when called with no submitter argument.
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-form-submit
const submitter_html: ?*HtmlElement = blk: {
const s = submitter_ orelse break :blk null;
if (s == form_element) break :blk null;
break :blk s.is(HtmlElement);
};
const submit_event = (try SubmitEvent.initTrusted(comptime .wrap("submit"), .{ .bubbles = true, .cancelable = true, .submitter = submitter_html }, self)).asEvent();
// so submit_event is still valid when we check _prevent_default

View File

@@ -485,12 +485,13 @@
}
</script>
<!-- Test: requestSubmit() without submitter sets submitter to the form element -->
<!-- Test: requestSubmit() without submitter sets SubmitEvent.submitter to null
per the HTML spec "submit a form element" algorithm step 4. -->
<form id="test_form_submitter2" action="/should-not-navigate7" method="get">
<input type="text" name="q" value="test">
</form>
<script id="requestSubmit_default_submitter_is_form">
<script id="requestSubmit_default_submitter_is_null">
{
const form = $('#test_form_submitter2');
let capturedSubmitter = undefined;
@@ -501,7 +502,7 @@
});
form.requestSubmit();
testing.expectEqual(form, capturedSubmitter);
testing.expectEqual(null, capturedSubmitter);
}
</script>