Knockout-Validation icon indicating copy to clipboard operation
Knockout-Validation copied to clipboard

How to access validation from inside the view model?

Open rudym87 opened this issue 11 years ago • 3 comments

The latest release broke my validation flow, because previously i was able to call .isValid() and .showAllMessages() from inside my view model without manually creating a group but by simply calling ko.validatedObservable(new MyViewModel()). Adding a validatedObservable to the view model like self.validation = ko.validatedObservable(self) creates a circular reference which prevents immediate serialization. The only workaround that I've found is creating a temporary validatedObservable variable each time I have to validate my view model. Are there any better options?

rudym87 avatar Jan 21 '15 16:01 rudym87

The return value of ko.validation.group no longer attaches those properties to the view model. Instead these properties go on the return value - except isValid which is equivalent of result().length === 0. I've created a simple fiddle for this purpose. http://jsfiddle.net/rsu2eq9j/

Consider checking the release notes for other breaking changes that might affect your code.

crissdev avatar Jan 21 '15 17:01 crissdev

@rudym87 Can we close this?

crissdev avatar Feb 08 '15 23:02 crissdev

Yes, go ahead. Thanks for your fiddle.

rudym87 avatar Feb 09 '15 15:02 rudym87