Re: NSFormatter problem when dialog box closed
Re: NSFormatter problem when dialog box closed
- Subject: Re: NSFormatter problem when dialog box closed
- From: Matt Neuburg <email@hidden>
- Date: Sat, 13 Jul 2002 12:17:31 -0700
On Thu, 11 Jul 2002 16:01:51 -0600, John Nairn <email@hidden> said:
>
I have an NSFormatter on an NSTextField in a modal dialog sheet. It
>
works correctly as I tab around fields, but when I click OK, the dialog
>
sheet exits without verifying the format of the field. Thus I might end
>
with invalid text in the field
The first thing you should do in the OK button's action routine is to ask
the field to end editing. If it doesn't pass the validation tests opposed
upon it (such as a formatter, a delegate message
control:textShouldEndEditing, and so forth) the result will be NO and you
don't close the window.
If this is the only field and you know it's the one being edited, you can
do that directly with textShouldEndEditing:, but a more general and elegant
approach is to try to make the window its own firstResponder; for example:
if ([[sender window] makeFirstResponder: [sender window]]) ...
m.
--
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt
pantes anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.