diff --git a/Src/api.js b/Src/api.js index 056dc8f1..dc59b175 100644 --- a/Src/api.js +++ b/Src/api.js @@ -174,11 +174,7 @@ }); }; - obj.errors = result; - obj.isValid = function () { - return obj.errors().length === 0; - }; - obj.isAnyMessageShown = function () { + result.isAnyMessageShown = function () { var invalidAndModifiedPresent = false; // ensure we have latest changes diff --git a/Src/ko.extensions.js b/Src/ko.extensions.js index e19fe45f..f72982e7 100644 --- a/Src/ko.extensions.js +++ b/Src/ko.extensions.js @@ -36,7 +36,7 @@ ko.validatedObservable = function (initialValue, options) { var obsv = ko.observable(initialValue); obsv.errors = ko.validation.group(initialValue, options); - obsv.isValid = ko.observable(initialValue.isValid()); + obsv.isValid = ko.observable(obsv.errors().length === 0); if (ko.isObservable(obsv.errors)) { diff --git a/Tests/api-tests.js b/Tests/api-tests.js index bfef1798..b0fedf41 100644 --- a/Tests/api-tests.js +++ b/Tests/api-tests.js @@ -274,7 +274,7 @@ test('validatedObservable does not show error message when not modified', functi }); ok(obj(), 'observable works'); - ok(!obj().isAnyMessageShown(), 'validation error message is hidden'); + ok(!obj.errors.isAnyMessageShown(), 'validation error message is hidden'); }); @@ -288,7 +288,7 @@ test('validatedObservable does not show error message when modified but correct' obj().testObj2('a'); ok(obj(), 'observable works'); - ok(!obj().isAnyMessageShown(), 'validation error message is hidden'); + ok(!obj.errors.isAnyMessageShown(), 'validation error message is hidden'); }); @@ -301,7 +301,7 @@ test('validatedObservable show error message when at least one invalid and modif obj().testObj.isModified(true); ok(obj(), 'observable works'); - ok(obj().isAnyMessageShown(), 'validation error message is shown'); + ok(obj.errors.isAnyMessageShown(), 'validation error message is shown'); });