What is the recommended way to handle the validation following scenario with Breeze?
Scenario: I have an entity with
startDate
,endDate
anduseDate
fields. IfuseDate
is true, then I want to validatestartDate
andendDate
are valid dates and thatendDate
>startDate
.
The approach suggested in the Breeze documentation is to create a custom Validator and register it on the entity. The issue I see with this approach is that I would then need to manually call validateEntity()
every time one of those three properties changes in order to have the validation errors added to the entity's error collection. The other recommended method of adding a custom validator on a single property doesn't provide access to the entity (just the current property value) so this isn't a great option either.
I could subscribe to each Knockout property changed event on the entity and then invoke validateEntity()
but this seems clumsy.
Is there any way to add a custom entity-level validator to an entity but associate it with one or more properties so that when one of the associated properties change, the entity-level validator is invoked? It seems like Breeze is missing a common validation use case scenario here, but I'm probably missing something.
Thanks, Richard