I would like to solicit additional information from the user during the NSOpenPanel but need to validate that information before the open panel completes. For example, I may want to allow the user to add a note about the file in the open panel selection but need to validate that that comment is not empty.
I have an accessory view whose controls are bound to an NSObjectController
whose content object in turn is bound to the represented object of the NSViewController that I use to load the accessory view's nib. The represented object has NSKeyValueCoding
-compliant validation methods (e.g. -(BOOL)validateKey:error:
). Validation is correctly handled (and violations reported via modal dialog) when the user modifies the values of the controls.
My problem is that I can't figure out how to get validation if the user doesn't enter anything in the accessory view. For example, say I have a single text field in the accessory view whose bound object validates that the text is non-zero in length. If the user enters text (validation succeeds), then deletes the text, validation fails and the user is presented with the error. However, if the user doesn't enter text, the open panel dismisses without error. How can I validate that the text is non-zero before the open panel dismisses?