On Mar 24, 2016, at 9:29 PM, Rick C. <[email protected]> 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 protected]) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
