I’ve been struggling to configure Knockout Validation to use Bootstrap error classes and form-control-feedback element. Finally, it’s working and now I’m going to brag about it. It’s quite simple really ;-)
-
<div class="form-group has-feedback" data-bind="validationElement: myVar">
-
<label class="control-label" for="myVarId">Queue Name</label>
-
<input id="myVarId" class="form-control" type="text" data-bind="textInput: myVar" />
-
</div>
-
-
<script type="text/html" id="myErrorTemplate">
-
<span class="help-block" data-bind="text: field.error, visible: field.isModified()"></span>
-
<span class="glyphicon glyphicon-remove form-control-feedback" data-bind="visible: field.isModified() && !field.isValid()"></span>
-
</script>
The interesting javascript part is just the configuration. Your validation rules and model bindings/observables are the usual:
-
span class=”st0″>’has-error’,
-
messageTemplate: ‘myErrorTemplate’
-
});