Skip to content

Checkboxes for non-nullable booleans fail validation when generated using @(Html.CheckBox() or @(Html.CheckBoxFor(m => m) #7940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aleksandarevangelatov opened this issue Aug 15, 2024 · 0 comments
Assignees
Labels
Bug C: Checkbox FP: Completed Sync status with associated Feedback Item Regression Broken functionality which was working previously S: Wrappers (ASP.NET Core) S: Wrappers (ASP.NET MVC) SEV: High
Milestone

Comments

@aleksandarevangelatov
Copy link
Contributor

Bug report

Checkboxes for non-nullable booleans fail validation when generated using @(Html.CheckBox() or @(Html.CheckBoxFor(m => m)

Related to #7798

Reproduction of the problem

Model:

public bool Shipped { get; set; }

Implement an editable Grid and use a Boolean template for an editor where @(Html.CheckBoxFor(m => m) is used.

Current behavior

Upon saving the checkbox validation fails.

Expected/desired behavior

Validation shall succeed.

Workarounds

  1. Use a nullable bool if the checkbox should not be validated - public bool? Shipped { get; set; } or
  2. Use a Telerik UI Checkbox instead - @(Html.Kendo().CheckBoxFor(m => m) or
  3. Remove the generated data-val-required attribute when the checkbox is rendered - $('input[type="checkbox"]').removeAttr('data-val-required'); (use a more specific selector if needed) or
  4. Define a custom Boolean.cshtml editor and place it in ~Views\Shared\EditorTemplates\ folder where the visible <input type="checkbox" \> is wrapped in a container element and the data-val-required attribute is missing.
@model bool
@{
    var name = Html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName("");
}

<div>
    <input id="@name" name="@name" type="checkbox" value="true" data-bind="checked:@name">
</div>
<input name="@name" type="hidden" value="true" data-bind="value:@name">
<span class="field-validation-valid" data-valmsg-for="@name" data-valmsg-replace="true"></span>

Environment

  • Kendo UI version: 202x.r.ddd
  • jQuery version: x.y
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
@aleksandarevangelatov aleksandarevangelatov self-assigned this Aug 15, 2024
@github-actions github-actions bot added the FP: Unplanned Sync status with associated Feedback Item label Aug 15, 2024
@aleksandarevangelatov aleksandarevangelatov added the Next Release Item that will be included in the next official release label Oct 24, 2024
@github-actions github-actions bot added FP: Completed Sync status with associated Feedback Item and removed FP: Unplanned Sync status with associated Feedback Item labels Oct 24, 2024
@aleksandarevangelatov aleksandarevangelatov added this to the 2024 Q4 (Nov) milestone Oct 24, 2024
@kendo-bot kendo-bot removed the Next Release Item that will be included in the next official release label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug C: Checkbox FP: Completed Sync status with associated Feedback Item Regression Broken functionality which was working previously S: Wrappers (ASP.NET Core) S: Wrappers (ASP.NET MVC) SEV: High
Projects
None yet
Development

No branches or pull requests

2 participants