I'm trying to increase compatability between jQuery validation and knockout validation plugins so that the same rules (admittedly a subset of functionality) can be used on both in different places in my application.
One of the areas to tackle is that jQuery validation has different capitalization for minlength, maxlength etc (KO uses minLength). I'd hoped to be able to create a simple alias...
$.validator.addMethod("minLength", function(value, element, params) {
return $.validator.methods.minlength(value, element, params);
});
which seems sufficiently simple to bridge the gap. However, this throws "this.optional is not a function" when it hits the jQuery validator here
// http://docs.jquery.com/Plugins/Validation/Methods/minlength
minlength: function(value, element, param) {
return this.optional(element) || this.getLength($.trim(value), element) >= param;
},
I'm guessing I need to pass the correct "this" context in somehow?