• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSFormatter Question: NSTextField should not be left blank
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSFormatter Question: NSTextField should not be left blank


  • Subject: NSFormatter Question: NSTextField should not be left blank
  • From: Heiko <email@hidden>
  • Date: Sun, 9 Jun 2002 20:55:53 +0200

Hi,

I got stuck with a NSFormatter which should prevent the user from leaving NSTextFields (and NSSecureTextFields) blank.

It was pretty easy to create a NSFormatter instance with:

- (BOOL)getObjectValue:(id *)obj forString:(NSString *)string errorDescription:(NSString **)error
{
BOOL retval = NO;
NSString *err = nil;

NSLog(@"PasswordFormatter: getObjectValue: %@", string);

if ([string cStringLength]<kPasswordMinLen || [string isEqual:@""] )
{ /* Password String is too short! */
err = NSLocalizedStringFromTable(@"ProjectWPasswordTooShort", @"Localizable", @"");
NSLog(@"PasswordFormatter: Password String is too short!");
}
else
{ /* String is allright -> OK */
retval=YES;
*obj=[NSString stringWithString:string];
NSLog(@"PasswordFormatter: Password String is OK!");
}
/* Falls das Gegen|ber Fehlermeldungen mag, kann er sie haben! */
if (error) *error = err;

return retval;
}

I see in the console that my routine gets fired as the user clicks into another field (leaves the password-Field which is empty).

But: The control's delegate's didFailToFormatString doesn't fire.

BUT: If I type something, then delete it, so that the field is blank again, and I THEN leave the field, the didFailToFormatString fires.

It seems that the getObjectValue: method gets called on all clicks. But if it returns an error (no valid string in field), it only fires the control's didFailToFormatString only if there was a keydown event.

Is this a bug or normal behaviour? Anyway, is there a way to implement this functionality?

--
Heiko
--
"...one of the main causes of the fall of the Roman Empire was that, lacking
zero, they had no way to indicate successful termination of their C
programs." -- Robert Firth
_______________________________________________
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.

  • Follow-Ups:
    • Re: NSFormatter Question: NSTextField should not be left blank
      • From: Mike Vannorsdel <email@hidden>
  • Prev by Date: Re: Process Manager
  • Next by Date: Re: NSFormatter Question: NSTextField should not be left blank
  • Previous by thread: Re: Process Manager
  • Next by thread: Re: NSFormatter Question: NSTextField should not be left blank
  • Index(es):
    • Date
    • Thread