Why form.submit() Skips Required Field Validation and How form.requestSubmit() Fixes ItBrief · digest for November 23
Brief≈ 2 min

Why form.submit() Skips Required Field Validation and How form.requestSubmit() Fixes It

You bind form submission to Ctrl+Enter or a button in a modal footer, call form.submit(), and an empty order flies straight to your server. Attributes like required and type="email" simply didn't run.

The legacy form.submit() barges straight through: it bypasses the browser's built-in Constraint Validation API and never fires the submit event, so any preventDefault() handlers stay silent. Previously, developers had to call form.reportValidity() manually or click a hidden button.

form.requestSubmit() fixes this in one line. It mimics a real click: validates fields with native tooltips first, and only then dispatches submit. You can even pass an external submitter button linked via the form attribute:

<form id="order-form">
  <input name="email" type="email" required />
</form>
<!-- External button linked via the form attribute -->
<button id="save" type="submit" form="order-form">Сохранить</button>

<script>
  const form = document.querySelector('#order-form');
  const saveBtn = document.querySelector('#save');

  // Bad: skips required checks and the submit event
  // form.submit();

  // Good: validates fields and triggers submit
  form.requestSubmit(saveBtn);
</script>

It has been Baseline Widely Available since September 2022, requiring no polyfills. There is just one catch with the submitter argument: pass something that isn't a submit button (like a <div> or <button type="button">), and you get a TypeError. Pass a button belonging to a different form, and it throws a DOMException (NotFoundError).

Want a deep diveVotes help us choose what to break down in detail. This material has 0 votes.
Sources · 2