How can I enforce to select only one option of the checkboxes being equal to "true" of a group? It can be with jQuery or Data Annotations...
Because currently you can submit with all being false, and I don't want to allow that, I want that only one of them must and need to be true, otherwise the submit won't work.
<div class="row">
@Html.LabelFor(model => model.Question1CB1, htmlAttributes: new { @class = "control-label col-sm-2" })
<div class="col-sm-1">
<div class="checkbox">
@Html.CheckBoxFor(model => model.Question1CB1, new { @class = "Question1CBs" })
@Html.ValidationMessageFor(model => model.Question1CB1, "", new { @class = "text-danger" })
</div>
</div>
@Html.LabelFor(model => model.Question1CB2, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-sm-1">
<div class="checkbox">
@Html.CheckBoxFor(model => model.Question1CB2, new { @class = "Question1CBs" })
@Html.ValidationMessageFor(model => model.Question1CB2, "", new { @class = "text-danger" })
</div>
</div>
@Html.LabelFor(model => model.Question1CB3, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-sm-1">
<div class="checkbox">
@Html.CheckBoxFor(model => model.Question1CB3, new { @class = "Question1CBs" })
@Html.ValidationMessageFor(model => model.Question1CB3, "", new { @class = "text-danger" })
</div>
</div>
</div>
The checkboxes already work that it can only be selected one of them.
<script>
$(document).ready(function () {
$('.Question1CBs').click(function () {
$('.Question1CBs').not(this).prop('checked', false);
});
});
</script>