Change NSTextField text color, based on validation (bind)
I have a NSTextField with bindings that uses validation - if the value is invalid, the set is never called; if the user tries leave the field with an invalid value, the application shows an error alert with 2 choices (discard or continue editing), and so on...
To have a better UI, I want to change the text color within the validation:
-(BOOL)validateMinValue:(id *)ioValue error:(NSError * __autoreleasing *)outError
{
ParameterValue * param=*ioValue;
if(*ioValue==nil || param.internalValue>_data->maxValue)
{
if (outError != NULL) {
NSString *errorString = @"Minimum value must be less than the maximum value.";
NSDictionary *userInfoDict = @{ NSLocalizedDescriptionKey : errorString };
*outError = [[NSError alloc] initWithDomain:@"minValue-maxValue"
code:1
userInfo:userInfoDict];
}
_minValueField.textColor=[NSColor redColor];
return NO;
}
_minValueField.textColor=[NSColor whiteColor];
return YES;
}
The problem is that, if the users tries to leave the field with an invalid value and if he chooses the "discard change" option on the alert, the value is discarded, but the textcolor continues red (because the systems doesn't re-validate the value that it knows that is valid). Any suggestions?
链接地址: http://www.djcxy.com/p/85254.html