From 18680f2c66acdbbae3c4c1b99df99a48d8776795 Mon Sep 17 00:00:00 2001 From: austins <1623983+austins@users.noreply.github.com> Date: Tue, 26 May 2026 22:04:51 -0700 Subject: [PATCH 1/2] fix: skip HTML5 required attribute for bool properties --- .../Internal/RequiredAttributeAdapter.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Finbuckle.Html5Validation/Internal/RequiredAttributeAdapter.cs b/src/Finbuckle.Html5Validation/Internal/RequiredAttributeAdapter.cs index 794035a..68616a4 100644 --- a/src/Finbuckle.Html5Validation/Internal/RequiredAttributeAdapter.cs +++ b/src/Finbuckle.Html5Validation/Internal/RequiredAttributeAdapter.cs @@ -35,6 +35,14 @@ public override void AddValidation(ClientModelValidationContext context) throw new ArgumentNullException(nameof(context)); } + // ASP.NET Core marks bool with RequiredAttribute. Don't add the HTML5 required attribute for bool + // as it would cause unchecked checkboxes to block form submission in the browser. + // This matches the behavior of the built-in client-side validation. + if (context.ModelMetadata.ModelType == typeof(bool)) + { + return; + } + MergeAttribute(context.Attributes, "required", ""); MergeErrorMessageTitle(context); } From fd9b8cadfcc55898d68221511012e9a861eb8418 Mon Sep 17 00:00:00 2001 From: austins <1623983+austins@users.noreply.github.com> Date: Tue, 26 May 2026 22:04:51 -0700 Subject: [PATCH 2/2] fix: skip HTML5 required attribute for bool --- .../Internal/RequiredAttributeAdapter.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Finbuckle.Html5Validation/Internal/RequiredAttributeAdapter.cs b/src/Finbuckle.Html5Validation/Internal/RequiredAttributeAdapter.cs index 794035a..68616a4 100644 --- a/src/Finbuckle.Html5Validation/Internal/RequiredAttributeAdapter.cs +++ b/src/Finbuckle.Html5Validation/Internal/RequiredAttributeAdapter.cs @@ -35,6 +35,14 @@ public override void AddValidation(ClientModelValidationContext context) throw new ArgumentNullException(nameof(context)); } + // ASP.NET Core marks bool with RequiredAttribute. Don't add the HTML5 required attribute for bool + // as it would cause unchecked checkboxes to block form submission in the browser. + // This matches the behavior of the built-in client-side validation. + if (context.ModelMetadata.ModelType == typeof(bool)) + { + return; + } + MergeAttribute(context.Attributes, "required", ""); MergeErrorMessageTitle(context); }