Hi,
  I have a need for a complex data-entry form (window). Some fields are 
supposed to only accept alpha characters (upper or lower), some are supposed to 
only take integers, others to only take floats (but no negative values 
allowed). Is there a general way of validating the contents of a field before 
it resigns first responder status? Even better, is there a way to encapsulate 
that behavior in an NSTextField subclass so that I can make, say, an 
AlphaOnlyTextField class, drag a (normal) NSTextField onto the window in IB, 
then change it's super to "AlphaOnlyTextField", or some such? This way I can 
save a lot of time, and will have a reusable control (sub)class that I can then 
use in other projects!
  I'm still using Xcode 3.somethingorother, and IB for my MacOS X/iOS work.
  Here's the control flow I hope to tap into:

Control (an NSTextField) has focus (is first responder) - user types something 
into the NSTextField
User tabs (or shift-tabs) to the next control, or clicks the mouse on another 
control
NSTextField that currently has first responder status checks to see if it has a 
delegate, and - if it does - does it respond to validate:? If so, the delegate 
gets sent the validate: message which returns a BOOL. If the control's contents 
(it's stringValue in the case of an NSTextField) has valid input, it'll return 
YES to indicate that the control may lose first responder. If it returns NO, 
then the attempt to lose first responder status is nullified, and the control 
keeps its first responder status.
User finally types in valid input, and the validate: returns YES. The 
NSTextField now loses first responder, and some other control on the view now 
gets first responder status.

Doable? Basically, I'd like to subclass NSTextField and the subclass would 
implement the delegate protocol's validate: message (method); the subclass 
would set itself as it's own delegate in the awakeFromNib: method, then remove 
itself somewhere else (when the control, and it's parent window, dies.) Even 
better, can I trap (and kill) invalid characters as they're entered? (i.e. an 
NSTextField that only allows (A-Z | a-z), and converts the characters to upper- 
or lower-case, say?


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to