I'd like to extend ngForm & ngModel to shift the responsibility for validations onto the model, such that a mock object would look like:
user = {
name: '',
email: '',
zip: '',
id: '',
validates: {
name: { presence: true },
email: { presence: true, email: true },
zip: { presence: true, zip: [ zipValidator, "Must contain a valid zip code" ] }
},
save: angular.noop,
find: angular.noop
};
The test suite I've written passes fine when I actually go in and flat out change Angular, but I'd really prefer to shift to leave Angular itself alone. I tried moving off my work to form and ngModel directives that require form and ngModel's controllers, but when Angular evaluates the template, it calls ng-model, which calls formCtrl.$addControl before my directives have an opportunity to load, and thus my extensions never happen.
Anyone know of any way to do this? Here's a gist of the changes I'm making:
Best,
Brett