Validate a user entry
Validate a user entry
- Subject: Validate a user entry
- From: Michèle Garoche <email@hidden>
- Date: Wed, 19 Dec 2001 05:58:42 +0100
From a newbie:
In Travel Advisor in Learning Cocoa, there is a field validation
implemented as follow:
- (void)awakeFromNib
{
...
[currencyRateField setDelegate:self];
...
}
- (BOOL)control:(NSControl *)control isValidObject:(id)obj
{
if (control == currencyRateField)
{
if ([obj floatValue] <= 0.0)
{
NSRunAlertPanel(@"Travel Advisor",
@"Rate cannot be zero or negative.", nil, nil, nil);
return NO;
}
}
return YES;
}
It works only (not surprisingly) when the user enters a value in the
field.
Should I implement a second method so that it works also when the user
tabs through the field without entering a value. Which method and how
to implement it ?
And a third one when the user adds the record (in case he did not even
go into the field). Again which method and how to implement it.
Any help would be greatly appreciated.