View Single Post
I am using OASteppableTextField and would like to submit an improvement to it - not sure if there is some recommended way to do this, so will post the code here.

The issue: OASteppableTextField does not transform the values using a value transformer that may be attached to the binding.

Solution: look for either a transformer object or transformer name in the binding options and transform the value using it, if there is one. There are no API changes or side effects from this improvement. I have tested this fix and it works nicely. Would appreciate a note in the commit notes if you include this in a future version of the framework, so I don't have to remember to edit it each time.

Here is the revised method with comments at the start and end of the change:

- (BOOL)_stepWithFormatterSelector:(SEL)formatterSel ector;
{
NSFormatter *formatter = [self formatter];
if (![formatter respondsToSelector:formatterSelector])
return NO;

id objectValue = [formatter performSelector:formatterSelector withObject:[self objectValue]];
if (![self validateSteppedObjectValue:objectValue])
return NO;

[self setObjectValue:objectValue];
[NSApp sendAction:[self action] to:[self target] from:self];

NSDictionary *bindingInfo = [self infoForBinding:@"value"];
/****** START IMPROVEMENT *********/
if (bindingInfo) {
NSDictionary *bindingOptions = [bindingInfo objectForKey:NSOptionsKey];
if ([bindingOptions objectForKey:NSValueTransformerBindingOption]) {
NSValueTransformer *transformer = [bindingOptions objectForKey:NSValueTransformerBindingOption];
objectValue = [transformer reverseTransformedValue:objectValue];
} else if ([bindingOptions objectForKey:NSValueTransformerNameBindingOption]) {
NSValueTransformer *transformer = [NSValueTransformer valueTransformerForName:[bindingOptions objectForKey:NSValueTransformerNameBindingOption]];
objectValue = [transformer reverseTransformedValue:objectValue];
}

[[bindingInfo objectForKey:NSObservedObjectKey] setValue:objectValue forKeyPath:[bindingInfo objectForKey:NSObservedKeyPathKey]];
}
/********* END IMPROVEMENT **********/
return YES;
}