This is the definition from the source code and the only place it is used in the source is knockout.validation.js .
validatedObservable( ) is & ndash; and this one.
ko.validatedObservable = function (initialValue) { if (!kv.utils.isObject(initialValue)) { return ko.observable(initialValue).extend({ validatable: true }); } var obsv = ko.observable(initialValue); obsv.errors = kv.group(initialValue); obsv.isValid = ko.observable(initialValue.isValid()); obsv.errors.subscribe(function (errors) { obsv.isValid(errors.length === 0); }); debugger; return obsv; };
In my experience, this is more of a problem than it costs - for example, it does not have the ability to specify a “deep” for the created “group”, and I think that it is really intended only for simple objects of the “one level” js.
If you have a complex model, your best bet is to do something similar and create an array of objects that you really want to check:
var validatables = []; // if credit card is payment then validate payment details + address if (this.paymentMethod() == "Credit Card") { validatables.push(this.paymentDetails); validatables.push(this.billingAddress); if (this.shipToBillingAddress() == false) { validatables.push(this.shippingAddress); } } var group = ko.validation.group(validatables, { deep: true });
source share