I have a view model as such:
var prop1 = ko.observable().extend{ required: true },
prop2 = ko.observable().extend{ required: true };
var validation = ko.validatedObservable([prop1, prop2]);
function resetFields() {
prop1(undefined);
prop2(undefined);
}
var vm = {
prop1: prop1,
prop2: prop2,
validation: validation,
reset: resetFields
};
The properties prop1 and prop2 are being validated correctly via the validatedObservable, however when I execute resetFields, these properties then have errors on them since they've been modified and are required.
Is there a way to reset the validated observable, as if it had not been changed?
Update: I was sourcing knockout.validation from NuGet, and using v1.0.1
showAllMessages(false)
only sets theisModied
observables to false which results in the error messages removed however it does not clear the validation result. So theisValid()
will remainfalse
:vm.reset(); console.log(vm.validation.isValid()); //output: false vm.validation.errors.showAllMessages(false) console.log(vm.validation.isValid()); //output: false
jsfiddle.net/CjsCS – Eras