Enable/disable validation rules
I ran into the need of enabling/disabling validation rules dynamically. Is it possible to add 'enabled' to the context of a validation rule. When disabled the validator could simply return 'true'.
I have the same need. And since extenders do not work on computed observables, there does not seem to be an alternative.
Carl Schroedl did some work on this, take a look here: https://github.com/carlschroedl/validatedviewmodel/wiki
@KurtJanssen ,
As @jbeall mentioned, the ValidatedViewModel would allow you to dynamically enable/disable rules, as well as some other functionality that helps you re-use your view models.
@enzoaeneas, Sorry, I'm not sure what you mean by 'extenders'. Could you clarify that a bit? I know that you can validate computed observables (see examples in the ValidatedViewModel unit tests), but maybe I misunderstand... is that what you were getting at?
@CarlSchroedl,
Yes. Since computed observable cannot be extended, which is how knockout validation works, I have run into the problem where I cannot turn validation on and off based on visibility of an element (which is in turn based on the value of another element or observable). I attempted to make the value validation based on a computed itself but it fails.
Covered by onlyIf option available for rules.