Hi,

I have a NSSecureTextField combined with bindings I need to filter for "allowed" formats like ['0'-'9']* or ['0'-'9''a'-'f']*.

The filter is set up like below and according to the NSLog working fine.
According to the documentation "Bindings Message Flow", the following should occur:

[12] The validation result, value, and a possible error are returned by the controller’s validateValue:forKeyPath:error:method to the view. [13] If the validation result is YES, then the valid or coerced value are returned to Step 5, otherwise proceed to Step 14. [5] The view object invokes setValue:forKeyPath: on the controller object, passing the new, possibly transformed, object value and the binding’s key path as arguments.

However, when e.g. "12xxx" is coerced to "12", in the TextField still five bullets remain and entering another digit invokes the method with "12xxx1". How can I force the documented behavior?

- (BOOL) validateValue:(id *) ioValue forKey:(NSString *) anKey error: (NSError **)outError
{
        if( [anKey isEqualTo:@"myKey"] )
        {
                NSString *value = *ioValue;
unichar *buffer = (unichar *) malloc( [value length] * sizeof( unichar) );
                unichar *dest = buffer;
                
                for( NSInteger i = 0; i < [value length]; ++i )
                {
if( [oValidator inputMethodAllowsCharacter:[value characterAtIndex:i]] )
                        {
                                *dest = [value characterAtIndex:i];
                                ++dest;
                        }
                }
                
                NSUInteger len = (dest - buffer);
NSString *coercedValue = [NSString stringWithCharacters:buffer length:len];
                free( buffer );
                *ioValue = coercedValue;
                
                NSLog( @"%s %...@->%@", __PRETTY_FUNCTION__, value, 
coercedValue );
                return (coercedValue != nil);
        }
        return YES;
}


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to