The view model seems to be the most appropriate place to perform validation yet Angular seems to be pushing me down the popular form validation route.
Why Model Validation?
- DRY - Applying validation to the model will centralize the validation logic as opposed to repeating it in every view.
- Unit Testable - Since the logic isn't coupled in the HTML we are able to apply unit testing to our validation logic.
- Shared Models - Shared view models can be validated regardless of what controller they interact with.
What I've looked into...
I've looked into creating a JSON schema to define a valid model with the following schema authority...
Whilst this is a viable option, I feel I am constraint to the schema and can therefore not apply custom validation or messages.
I feel like I need a mature validation library to handle this model validation but cannot find anything online to fit my needs.
How can you help?
I'm keen to know if other developers have had a similar experience and what their approach was. Have you found a viable model validation solution or have you stuck with form validation?