Each exercise/workout is uniquely identified by its name
property. Thus, before persisting for the first time, we need to make sure that the user has entered a unique name for the workout/exercise. If the exercise/workout already exists with this name, we need to inform the user with the appropriate validation message.
This can be achieved by performing some custom validation logic in the controller's save
function and binding the result to some validation label in the view. Instead, a better approach will be to create a validation directive, which can be integrated with the form validation infrastructure for consistent user experience.
Note
In Chapter 4, Building Personal Trainer, we touched upon Angular form validations and how it works, but did not create a true custom validator. We are going to build one now using a directive.
We can either create a directive specifically for unique name validation or a generic directive...