I have following attributes in my viewmodel which use knockout validation,one of them is custom validation to check password match.
model.Password = ko.observable()
.extend({ required: { message: "Password is required.",
params: true,
onlyIf: function () { return model.IsCredentialsRequired(); }}
});
model.ConfirmPassword = ko.observable().
extend({ validation: { validator: mustEqual,
message: 'Passwords do not match.',
params: model.Password,
onlyIf: function () { return model.IsCredentialsRequired(); } }
});
code for custom validation function
var mustEqual = function (val, other) {
return val == other();
};
I found that OnlyIf
condition is working fine for model.Password
depending on model.IsCredentialsRequired()
but its not working for model.ConfirmPassword
,Can somebody help me why this is happening?Is there any another way by which i can use conditional validation for custom rules?
Thanks in advance