Create A Thing

This form does the normal individual attribute validation as described in theSize Creator Component.  It also implements the -validateForSave method to validate that the length of the name is less than the volume of the selected Size (the name has to fit somewhere in this rather arbitrary example of business logic). Because this validation requires validating both the contents of an attribute on the Thing and an attribute that can only be had by traversing a relationship, it must be done in validateForSave. The action method for the form must, therefore, catch any exceptions on the attempt to save and create an appropriate error message.

In this application, the error messages are generated from the reason attribute of the various exceptions. This is not the right way to do this. In the real world, the reason or the exception's name or some key/value pair would likely be used to look up a localized version of the string via NSBundle's localizedStringForKey: method.

To trigger the validation, click the Create button after:

Name: 
Choose A Size: 
Already Created Things:
(Maximum volume )