Currently the Knockout-Validation plugin automatically add this HTML element to my web page:
<span class="validationMessage">This field is required.</span>
<span>
HTML element..err
, specifically) to my textbox so that I can add a red border.How can that be done with Knockout-Validation?
Finally, the positioning of your error messages are key. This all comes down to good User Experience design practice. Logical positioning not only saves you further detailing the situation, but also allows the user to quickly see where they are going wrong and – that word again – recover!
Top of Form Validation Vs. Inline Validation The two most common placements for error messages are at the top of the form and inline with erroneous fields.
An error message is information displayed when an unforeseen problem occurs, usually on a computer or other device. On modern operating systems with graphical user interfaces, error messages are often displayed using dialog boxes.
You can change the default messages for a validation on a per property basis:
test: ko.observable().extend({
required: {
params: true,
message: "This is required"
}
})
You can use the validationMessage
binding to display the errors wherever you want:
<span data-bind="validationMessage: test"></span>
And you can use the decorateElement
and errorElementClass
options (or the other validation bindings) to add some custom classes on your inputs:
ko.validation.init({
decorateElement: true,
errorElementClass: 'err'
});
Demo JSFiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With