Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
HTML

HTML5: Fix a Form’s required Attribute Skipped on Enter

- 19.11.26 - ErcanOPAK

đź§© Fix a Form’s required Attribute Skipped on Enter

Pressing Enter inside a text input triggers the browser’s implicit form submission, which normally runs the same constraint validation as clicking a submit button — but when a form has multiple buttons, or a plain `<button>` with no explicit `type` elsewhere in the markup, browsers resolve the Enter key to whichever button the spec treats as the form’s default, and if THAT button carries `formnovalidate` (common on a “Save Draft” action), pressing Enter submits the form through a path that was never meant to skip validation, bypassing every `required` field’s check that a deliberate click on the real submit button would have enforced.

🔎 The Problem

<form id="signup">
  <input type="text" name="email" required>
  <!-- A hidden, always-present, non-formnovalidate submit button
       guarantees Enter resolves to a path that still validates -->
  <button type="submit" style="position:absolute;left:-9999px;"
          aria-hidden="true">Submit</button>
  <button type="submit" formnovalidate id="save-draft">Save Draft</button>
</form>

âś… Fix: Give Enter a Button That Still Validates

  • Make sure exactly one real `<button type=”submit”>` without `formnovalidate` comes before any other button in DOM order, since that’s the one browsers resolve Enter-key implicit submission to — a visually hidden one works fine if your visible submit button is actually later in the markup.
  • Explicitly mark any non-validating action (“Save Draft”, “Cancel”) with `type=”button”` or `formnovalidate` rather than leaving its `type` to default, since a plain `<button>` inside a `<form>` defaults to `type=”submit”` and can silently become the Enter-key target.
  • Add a `submit` event listener that itself calls `form.reportValidity()` as defense-in-depth, so even if a browser’s default-button resolution differs from what you expect, validation still runs before anything reaches the server.

🚨 Why This Is Dangerous

  • A signup or payment form that skips `required` validation only on Enter, not on a deliberate button click, is exactly the kind of inconsistency manual testing misses — most testers click the button, while a meaningful share of real users just press Enter.

The browser’s idea of your form’s default button and your idea of it aren’t guaranteed to be the same button.

— Frontend Architect

Related posts:

HTML5 “Inputmode” — The Feature That Makes Mobile Forms 10× Better

HTML5 “Inputmode” — The Feature That Makes Mobile Forms 10× Better

HTML5: Fix the download Attribute on a Link Being Silently Ignored for Cross-Origin URLs

HTML5: Fix the download Attribute on a Link Being Silently Ignored for Cross-Origin URLs

Adım Adım: HTML ile Progressive Web App (PWA) Kurulumu

Adım Adım: HTML ile Progressive Web App (PWA) Kurulumu

Views: 4

Post navigation

Windows 11: Fix a Printer Queue Stuck After Waking From Sleep
SQL Server: Fix a Trigger Firing Twice on One Merge Statement

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,059)
  • Get the User Name and Domain Name from an Email Address in SQL (983)
  • How to add default value for Entity Framework migrations for DateTime and Bool (981)
  • Get the First and Last Word from a String or Sentence in SQL (861)
  • How to select distinct rows in a datatable in C# (856)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (658)
  • Add Constraint to SQL Table to ensure email contains @ (613)
  • Average of all values in a column that are not zero in SQL (571)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (549)
  • Find numbers with more than two decimal places in SQL (477)

Recent Posts

  • Visual Studio: Fix Quick Actions Hiding Behind a Stale Squiggle
  • Photoshop: Fix a Smart Filter Resetting After You Relink It
  • Ajax: Fix a Cancelled Request Still Updating Stale UI State
  • C#: Fix a Span Captured by a Lambda Throwing at Runtime
  • The AI Prompt That Converts a REST Endpoint Into a Typed SDK
  • Git: Fix a Worktree Locking a Branch Needed Somewhere Else
  • Asp.Net Core: Fix a Background Service Leaking Scoped Dependencies
  • SQL Server: Fix a Columnstore Index Fragmenting After Bulk Deletes
  • Docker: Fix a Container Losing Logs After a Restart Policy
  • Asp.Net Core: Fix Output Caching Serving a Stale Authorized Page

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,059)
  • Get the User Name and Domain Name from an Email Address in SQL (983)
  • How to add default value for Entity Framework migrations for DateTime and Bool (981)
  • Get the First and Last Word from a String or Sentence in SQL (861)
  • How to select distinct rows in a datatable in C# (856)

Recent Posts

  • Visual Studio: Fix Quick Actions Hiding Behind a Stale Squiggle
  • Photoshop: Fix a Smart Filter Resetting After You Relink It
  • Ajax: Fix a Cancelled Request Still Updating Stale UI State
  • C#: Fix a Span Captured by a Lambda Throwing at Runtime
  • The AI Prompt That Converts a REST Endpoint Into a Typed SDK

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com