mardi 5 décembre 2023

Blazor FluentValidation and invalid class on checkboxes

I am working with Blazor WASM and FluentValidation project. The validation works, but for checkboxes, the invalid class is not added to invalid checkboxes, when that object isnt valid.

For my radio button groups, the validation invalid class works fine, and the validation updates when you select a radio button making it valid. This is because I am binding to SelectedValues in the InputRadioGroup.

My validator has the following rule.

 RuleFor(r => r.SelectedValues).NotEmpty().NotNull().When(r => r.IsRequired).WithMessage(r => $" XXX is required.");

Then on my razor page, I have this..

<InputCheckbox class="form-check-input" @bind-Value="@x.Selected" CurrentValue="@x.Value" />

When viewing the page, the InputCheckbox has "form-check-input valid" which may not be correct. Again if I dont select anything, and click the submit button, the validation message appears, but it doesnt disappear when I check/select a checkbox making it valid, as well as the invalid css class isn't applied to the checkboxes.

Is it because I am validating SelectedValues, which in this case is a comma separated list, but the checkboxes aren't bound at all to that property? There isnt a grouping component like there is InputRadioGroup.

There may be a simple solution for this, but I havent figured it out yet.




Aucun commentaire:

Enregistrer un commentaire