How to observe validity of NSTextField+NSNumberFormatter?
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