Knockout-Validation
Knockout-Validation copied to clipboard
Allow params object without message property
When setting up validation, you can assign an value for comparison directly:
var myVal = ko.observable().extend({
minLength: 3,
});
Or you can assign an object if you want to customize the error message:
var myVal = ko.observable().extend({
minLength: {
params: 3,
message: "That is too short!"
},
});
I like to be consistent in how I set up my validation, regardless of whether I need to customize the message or not. So sometimes I'd like to do this (keeping the default error message):
var myVal = ko.observable().extend({
minLength: {
params: 3
},
});
But this doesn't work. ko validation compares the length of the value in my observable with { params: 3 } rather than comparing it with 3.
I suggest changing KO validation so that you can assign an object, such as my last example, even when there is no message property on that object.
If you like the idea I can work on a pull request.
I like the idea and I'll be happy to merge a PR for this.
I've created a demo for this to exibit the issue http://jsfiddle.net/tfmwLkds/ , in case someone else lands here and wants a visual feedback.