Re: Validating form input w/o core data
Re: Validating form input w/o core data
- Subject: Re: Validating form input w/o core data
- From: Graham Cox <email@hidden>
- Date: Wed, 28 Sep 2011 17:02:37 +1000
On 28/09/2011, at 11:41 AM, William Squires wrote:
> Is there a general way of validating the contents of a field before it resigns first responder status?
The preferred, supported way is to use a NSFormatter attached to the field. This has the ability to fully constrain and convert values to and from the field's text representation. This is designed to be subclassed. It's unusual to subclass NSTextField itself, especially as it's not the text field that is actually performing the text entry, but a hidden NSTextView called the field editor. Formatters can disallow the focus to be changed away from the text field if the content is not valid. To prevent characters from being entered as they're typed, you'll also want to use the field editor's delegate methods to reject unwanted characters (formatters only validate after the entry is submitted).
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden