In ASP.NET i have the following
public class TestController : Controller
{
public IActionResult Index()
{
return View(new MyModel()
{
Activities = new Activity[]
{
new Activity(){ },
new Activity(){ }
}
});
}
}
public class MyModel
{
public IList<Activity> Activities { get; set; }
}
public class Activity
{
public bool IsActive { get; set; }
}
cshtml
@model Metatasker.Integration.UI.Controllers.MyModel
<form id="myform">
@for (int i = 0; i < Model.Activities.Count; i++)
{
@Html.CheckBoxFor(x => x.Activities[i].IsActive)
}
</form>
<button id="btn">Click Me</button>
<script type="text/javascript">
$(function () {
function validate() {
var kendoValidator = $('#myform').kendoValidator().data("kendoValidator");
return kendoValidator.validate();
}
$("#btn").click(function () {
alert(validate());
})
})
</script>
I am using Kendo's Validate method to validate form. In code above when i have multiple CheckBoxes The validate() method always returns false. If i have single check box then it works.
I have jsfiddle demo. The html in jsfiddle is a rendered Razor view.
Try the following snippet.
You will notice that the validator treats only true values as inputs which are filled, else it serves up the required validation message. Each check box is validated individually.
So, I suggest using a custom rule.
There is also a demo which uses radio buttons, which you can refer to.