diff --git a/src/browser/Frame.zig b/src/browser/Frame.zig index 068587b0..28e0ef9a 100644 --- a/src/browser/Frame.zig +++ b/src/browser/Frame.zig @@ -4139,6 +4139,21 @@ pub fn submitForm(self: *Frame, submitter_: ?*Element, form_: ?*Element.Html.For form._firing_submission_events = true; defer form._firing_submission_events = false; + // Per the HTML "submit a form element" algorithm: unless the form (or the + // submitter, via formnovalidate) is in the no-validate state, interactively + // validate the form's constraints and abort submission if it fails. + // checkValidity() fires the `invalid` events on the offending controls. + // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-form-submit + const skip_validation = form.getNoValidate() or blk: { + const s = submit_button orelse break :blk false; + if (s.is(Element.Html.Form.Input)) |input| break :blk input.getFormNoValidate(); + if (s.is(Element.Html.Form.Button)) |button| break :blk button.getFormNoValidate(); + break :blk false; + }; + if (!skip_validation and !try form.checkValidity(self)) { + return; + } + // 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. diff --git a/src/browser/tests/element/html/form-validity.html b/src/browser/tests/element/html/form-validity.html index becce81d..1ce1b305 100644 --- a/src/browser/tests/element/html/form-validity.html +++ b/src/browser/tests/element/html/form-validity.html @@ -13,6 +13,8 @@
+ + + + + + + + +