• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Validating form input w/o core data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Validating form input w/o core data


  • Subject: Validating form input w/o core data
  • From: William Squires <email@hidden>
  • Date: Tue, 27 Sep 2011 20:41:43 -0500

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 (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

  • Follow-Ups:
    • Re: Validating form input w/o core data
      • From: Lee Ann Rucker <email@hidden>
    • Re: Validating form input w/o core data
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: controller question
  • Next by Date: Re: Equivalent of UITextField's textField:shouldChangeCharactersInRange:replacementString for NSTextField
  • Previous by thread: Re: Trouble creating dictionary
  • Next by thread: Re: Validating form input w/o core data
  • Index(es):
    • Date
    • Thread