Re: override NSTextField paste behavior
Re: override NSTextField paste behavior
- Subject: Re: override NSTextField paste behavior
- From: Ken Thomases <email@hidden>
- Date: Thu, 24 Mar 2016 22:47:40 -0500
On Mar 24, 2016, at 9:29 PM, Rick C. <email@hidden> wrote:
>
> I have an NSPanel with 2 NSTextFields and my controller is the delegate of the panel. I want to override the paste behavior of the 2 text fields so that the user doesn’t paste unnecessary spaces and other characters into these fields.
Is pasting really so special? Should the user be able to simply type such "unnecessary spaces and other characters" in the fields? Or do you want to prohibit that, too?
Probably the easiest approach is to create a custom subclass of NSFormatter and assign an instance of that formatter to each text field. The formatter would implement -isPartialStringValid:proposedSelectedRange:originalString:originalSelectedRange:errorDescription: to validate and even adjust the string as it's being edited, regardless of the manner of the edit operation (typing, pasting, etc.).
Regards,
Ken
_______________________________________________
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