• 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
Bindings + NS{Secure}TextField validation -> coerced value is not used
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bindings + NS{Secure}TextField validation -> coerced value is not used


  • Subject: Bindings + NS{Secure}TextField validation -> coerced value is not used
  • From: Thomas Engelmeier <email@hidden>
  • Date: Thu, 30 Apr 2009 15:13:47 +0200

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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Bindings + NS{Secure}TextField validation -> coerced value is not used
      • From: Alastair Houghton <email@hidden>
  • Prev by Date: Some Question about Core Animation in NSCollectionView
  • Next by Date: Re: NSScanner off-by-one and I can't see why...
  • Previous by thread: Some Question about Core Animation in NSCollectionView
  • Next by thread: Re: Bindings + NS{Secure}TextField validation -> coerced value is not used
  • Index(es):
    • Date
    • Thread