Clearing or resetting a knockout validation validatedObservable?

前端 未结 2 609
情深已故
情深已故 2021-02-07 14:36

I have a view model as such:

var prop1 = ko.observable().extend{ required: true },
    prop2 = ko.observable().extend{ req         


        
2条回答
  •  我寻月下人不归
    2021-02-07 14:52

    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.

提交回复
热议问题