You're right, you can't edit the formatter's error in control:didFailToFormatString:errorDescription: because the error description has already been determined.
You need to override the getObjectValue:forString:errorDescription: method of NSFormatter to set a custom error description. As for disallowing invalid characters while typing, which is probably what you want (in addition to an NSBeep() perhaps), you should look at the isPartialStringValid:newEditingString:errorDescription: method in NSFormatter. ---------------------------------------- > From: [email protected] > To: [email protected] > Date: Sun, 24 May 2009 13:30:30 -0500 > CC: > Subject: NSFormatter Question > > This is a newbie question, my apologies if it has been discussed in > the past. I haven't been programming on a Mac since the System 7 days > and trying to catch up with OS X and Cocoa... > > I have text field bound to an NSObjectController with an > NSNumberFormatter to ensure that there are only integer numbers > entered. Whenever I leave the field blank or enter invalid characters, > I get a very generic error message "Formatting Error". I'd like to > customize that error message with a hint for the user which values are > valid (similar to the message I get in the standard print dialog when > entering zero copies), but I haven't found a way to do so, except for, > perhaps, subclassing NSNumberFormatter. I had a look at - > control:didFailToFormatString:errorDescription:, but noticed that the > error description is not a mutable string, therefore I cannot pass > back a modified error message. Is there a way to customize the error > message without having to create a new subclass of NSNumberFormatter > for each field with a different format? > > On a related topic, if I set "Validates Immediately" on the binding of > that particular field, I was expecting to be stopped in my tracks as > soon as I enter, say, a letter instead of a number, but nothing > happens. It seems like the setting of the Validates Immediately flag > doesn't have any impact on the behavior. Am I missing something here? > _______________________________________________ > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/ulaibeekam%40hotmail.com > > This email sent to [email protected] _________________________________________________________________ Show them the way! Add maps and directions to your party invites. http://www.microsoft.com/windows/windowslive/products/events.aspx_______________________________________________ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
