Clearing or resetting a knockout validation validatedObservable?

百般思念 提交于 2019-12-03 05:43:26
nemesv

You cannot reset on the validatedObservable level but you can call clearError on the individual properties:

vm.reset();
console.log(vm.validation.isValid()); // output: false
prop1.clearError();
prop2.clearError();
console.log(vm.validation.isValid()); // output: true

Demo JSFiddle.

Note: It only works with a "recent" version of the validation plugin so the clearError is not included in the CDNJS and Nuget version of plugin. My JSFiddle demo uses the latest version (9fd5a4d2da) from GitHub.

When using a validated observable, I found out that you can call validatedObservable.errors.showAllMessages(false) after you have cleared the observable, which is behaving the way I was expecting in my application.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!