JSFiddle - React, Tailwind, and code Playground
by Aaron Hoffman
HTML
<script src="https://rawgithub.com/ericmbarnard/Knockout-Validation/master/Src/knockout.validation.js"></script>
<script id="koValidationCustomMessageTemplate" type="text/html">
<em class="text-danger" data-bind="validationMessage: field"></em>
</script>
<div class="col-sm-5" data-bind="foreach: TheCheckboxListOptions">
<div class="checkbox">
<label>
<input type="checkbox" data-bind="value: $data, checked: $root.TheCheckboxListSelectedValues" /><span data-bind="text: $data"></span>
</label>
</div>
</div>
JavaScript
ko.validation.configure({
registerExtenders: true,
messagesOnModified: true,
insertMessages: true,
parseInputAttributes: true,
messageTemplate: "koValidationCustomMessageTemplate"
});
var TheViewModel = {
TheCheckboxListOptions: [
"Option 1",
"Option 2",
"Option 3",
"Option 4"
],
TheCheckboxListSelectedValues: ko.observableArray().extend({
required: { message: "At least one option is required." }
}),
};
ko.applyBindings(TheViewModel);