Clear error on Knockout-Validation

2019-04-19 03:08发布

I have a page setup with Knockout.js and using Knockout-Validation.

During the page load I put another plugin on a select box which fires a change, which fires the validation. I need to be able to clear that error using JS so I can start with a fresh looking UI and give feedback on the form post or select box change.

I can't find anything that allows me to clear an error in Knockout-Validation.

4条回答
ゆ 、 Hurt°
2楼-- · 2019-04-19 03:32

Probably a better way that follows what is already implemented in knockout validation is to say property.isModified(false);

if you have a whole view model to reset simply loop through all the validated properties and call that isModified(false)

See the comment from Eric Barnard here

Hope that helps

查看更多
放我归山
3楼-- · 2019-04-19 03:43

If you use an entity manager make sure to not include the entityAspect in the validation since it is connected to all other entities. Also see How to rollback knockout validation errors?

查看更多
Evening l夕情丶
4楼-- · 2019-04-19 03:45

Found the answer by implementing this Pull Request.

https://github.com/Knockout-Contrib/Knockout-Validation/pull/184

Gives me the feature I need.

查看更多
淡お忘
5楼-- · 2019-04-19 03:52

Late answer but if anyone needs it :

// assuming the ko.observable on the checkbox is called propBoolean
var propBooleanlValid = ko.validation.group(self.propBoolean, { deep: false });
propBooleanlValid .showAllMessages(false);

It will hide the message till the next validation.

查看更多
登录 后发表回答