help-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to limit input in textfield?


From: Alexander Malmberg
Subject: Re: how to limit input in textfield?
Date: Sun, 01 Feb 2004 02:59:13 +0100

reuss wrote:
> If i would like to restrict the number of letters of user input in
> textfield (eg. max. 30 to put in database), how can i do it?

When using an NSTextView, you would implement
-textView:shouldChangeTextInRange:replacementString: in the delegate and
rejecting the change (by returning NO) if it would cause the string to
become too long. In an NSTextField, the text field instance sets itself
as the delegate for the NSTextView field editor, so you could write a
custom subclass of NSTextField that implemented
-textView:shouldChangeTextInRange:replacementString: and use that
instead of a plain NSTextField.

(An alternative would be to use formatters, but that isn't implemented
yet.)

- Alexander Malmberg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]