haacked / aspnet-client-validation

A client validation library for ASP.NET MVC that does not require jQuery

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Checkbox validation does not work (verified in demo app)

lonix1 opened this issue · comments

My model has a bool bound to a checkbox. It's not required, so I should be able to submit the form without checking it. But validation fails for the checkbox and I can't submit.

I tried the demo, and it also fails.

The demo has this:

    [BindProperty]
    public InputModel Input { get; set; } = new();

    // ...

    public class InputModel
    {
        [Remote("CheckboxRemote", "Validations", HttpMethod = "Post")]
        public bool IsChecked { get; set; }
    }

When trying to submit the form on the http://localhost:5000/Demos/Checkboxes page:

NET renders a checkbox and a hidden input ... it is unchecked. Unchecking it should not fail validation.

'IsChecked' is invalid. This is not checked

One can easily verify this repro, just run the demo, go to that page and click submit.

I think it's a bug.

The demo in question was added in #51 with a proposed fix for #48, but it was changed to include remote validation as of #83. I'm pretty sure "Unchecking it should not fail validation." is no longer true.

  1. If you remove the [Remote] does it work as expected?
  2. If so, could you split that demo into two (client-only and remote)?

Done: #91