Textfield and s default button
Textfield and s default button
- Subject: Textfield and s default button
- From: Freek Dijkstra <email@hidden>
- Date: Wed, 19 May 2004 01:12:05 +0200
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?
With kind regards,
Freek
_______________________________________________
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.