Re: Textfield and s default button
Re: Textfield and s default button
- Subject: Re: Textfield and s default button
- From: matt neuburg <email@hidden>
- Date: Wed, 19 May 2004 08:25:00 -0700
On Wed, 19 May 2004 01:12:05 +0200, Freek Dijkstra <email@hidden> said:
>
Hi,
>
>
A newbie question here.
>
>
I (well, my program) has a window with a few NSTextFields
>
and a default button. I've noticed that when the user
>
presses return while editing the NSTextField, the text is
>
validated, and if it is valid, the action method for the
>
text field is called, and after that has been done, the
>
action method for the default button is called.
>
>
This is what I want, because when the text is not
>
validated I want the operation to be cancelled, and if it
>
is valid, it makes sure that the action is called and the
>
value is updated to the model classes.
>
>
However, if the user clicks the default button with the
>
mouse, only the action methos for the default button is
>
called.
>
>
The latter is not what I want. Here, I also want the text
>
field to be validated first, and the action called. I
>
other words, I want the exact same behaviour if the user
>
presses return and if the users clicks the default button.
>
>
The solution I use so far is to traverse the window's
>
responder chain in the action method of the default
>
button, and for every NSControl (sub)class (like
>
NSTextField) I call these methods: validateEditing() and
>
sendActionToTarget (I retrieve the action with action()
>
and the target with target()). This works partially. One
>
thing I still need to do is to check if the text is valid
>
or not, and if it is not, give a beep to notify the user
>
the text is bad, and stop right there (not proceeding with
>
the action).
>
>
However, I really feel I'm duplicating existing
>
functionality here. So what is the best solution to this
>
problem: Do it this way, or is there some nifty mechanism
>
I missed?
The action of the button should first attempt to set the window's
firstResponder to nil. This will end editing and validate, returning false
if validation failed (in which case you just bail out). m.
--
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
AppleScript: the Definitive Guide! NOW SHIPPING...! (Finally.)
http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
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.