I'm using Knockout Validation to validate my model in a Durandal/KnockoutJS app. It's working fine, but I've run into a situation that I'm not sure how to handle. One of the things that users enter is a list of "instructors", and they can enter an arbitrary number of instructors. Each instructor has a "teaching percentage" value. The sum of all teaching percentages must add up to 100%.
I'm not sure how to setup the validation for this, because when I'm defining my model object for "Instructors", I can't reference an arbitrary number of other Instructor objects.
The best option I've been able to come up with is place a viewmodel computed observable that is the sum of all instructor teaching percentages, and validate that value as being 100.
Am I missing something? Is this a wise way to go about this situation? Broadly speaking, this question applies to any situation in which you have multiple model objects, and the validity of one of their properties is mutually dependent on properties on other objects.
E.g., ObjA.Heading is valid if it is a positive number, and ObjB.Heading is also positive; and the reverse is also true (ObjB.Heading is valid if it is a positive number, and ObjA.Heading is also positive).
Thanks for any input on how to handle this kind of situation.
Thanks!