I'm using the areSame
rule from here:
ko.validation.rules['areSame'] = {
getValue: function (o) {
return (typeof o === 'function' ? o() : o);
},
validator: function (val, otherField) {
return val === this.getValue(otherField);
},
message: 'The fields must have the same value'
};
And apply it like this:
this.confirm = ko.observable().extend({
areSame: {
params:this.password
}
});
But it's never even triggered. I put debugger into validator
function of the rule definition:
validator: function (val, otherField) {
debugger
return val === this.getValue(otherField);
},
however the flow never visits this point. What could be wrong?
EDIT:
The problem of not triggering validation is solved by calling ko.validation.registerExtenders();
, however the rule doesn't work as expected. The problem is that the otherField
variable, that is passed to validator
, is the object
{params:*observable here*}
, where as the method getValue
doesn't expect that as you can see from the source code. So either the source code is wrong or I defined the params for the rule in the wrong way. So which one?
ko.validation.registerExtenders()
to register your custom rule? – Sig