From 59d1da77c208e2b2b3a5334ee4e0b6dc0abce6ad Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Mon, 1 Apr 2013 12:47:00 -0700 Subject: [PATCH] Fixed: setting CPNullPlaceholderBindingOption in binding was setting the value This commit fix a bug where declaring the binding option CPNullPlaceholderBindingOption was actually setting the actual value of a text field instead of just its placeholder. This commit adds a test to determine if the binding source implements setPlaceholderString:. In that case, we let the value to be nil. --- AppKit/CPKeyValueBinding.j | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/AppKit/CPKeyValueBinding.j b/AppKit/CPKeyValueBinding.j index db0b238da..06ce850b7 100644 --- a/AppKit/CPKeyValueBinding.j +++ b/AppKit/CPKeyValueBinding.j @@ -257,7 +257,11 @@ var CPBindingOperationAnd = 0, if (valueTransformer) aValue = [valueTransformer transformedValue:aValue]; - if (aValue === undefined || aValue === nil || aValue === [CPNull null]) + // If the value is nil AND the source doesn't respond to setPlaceholderString: then + // we set the value to the placeholder. Otherwise, we do not want to short cut the process + // of setting the placeholder that is based on the fact that the value is nil. + if ((aValue === undefined || aValue === nil || aValue === [CPNull null]) + && ![_source respondsToSelector:@selector(setPlaceholderString:)]) aValue = [options objectForKey:CPNullPlaceholderBindingOption] || nil; return aValue;