• 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
How to observe validity of NSTextField+NSNumberFormatter?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to observe validity of NSTextField+NSNumberFormatter?


  • Subject: How to observe validity of NSTextField+NSNumberFormatter?
  • From: Rob Nikander <email@hidden>
  • Date: Fri, 23 Aug 2013 12:57:43 -0400

Hi,

I want to constrain an NSTextField to float values greater than zero, so I
connected an NSNumberFormatter in Interface Builder. Now the user can enter
invalid text (eg, "1a", "-2") but it beeps when you try to leave the field.
That may be okay.

Now I'd like to disable other parts of the UI when the field is invalid. I
connected a delegate to the NSTextField, and implemented
`controlTextDidChange:`, but I don't know how to check the validity from
within that method.  I get some strange behavior when I call
textField.doubleValue, or even textField.stringValue, from inside
controlTextDidChange.  It causes the textfield to behave differently --
instead of allowing invalid text and beeping later, it erases the invalid
text as soon as you type it.

So first question: why is that happening? What is getting called by
`textField.whateverValue` to change the field?

Second question: how to I ask the NSNumberFormatter about the validity of
the field as the field changes?  I'd call its `getObjectValue...` method
but I can seem to get the field's string value in `controlTextDidChange:`,
without changing the behavior as described above.

thanks,
Rob
_______________________________________________

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: How to observe validity of NSTextField+NSNumberFormatter?
      • From: Keary Suska <email@hidden>
    • Re: How to observe validity of NSTextField+NSNumberFormatter?
      • From: Rob Nikander <email@hidden>
  • Prev by Date: Re: Fastest way to replace characters in string
  • Next by Date: Audio in WebView stop when close NSWindow
  • Previous by thread: Re: NSWindow setMinSize: jumps up to current size instead
  • Next by thread: Re: How to observe validity of NSTextField+NSNumberFormatter?
  • Index(es):
    • Date
    • Thread