diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index c0abc894c..f0279caa9 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -258,6 +258,8 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); [self setStringValue:@""]; [self setPlaceholderString:@""]; + _originalPlaceholderString = undefined; + _sendActionOn = CPKeyUpMask | CPKeyDownMask; [self setValue:CPLeftTextAlignment forThemeAttribute:@"alignment"]; @@ -733,6 +735,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); /* @ignore + Sets the internal string value without updating the value in the input element */ - (void)_setStringValue:(id)aValue { @@ -806,16 +809,27 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); [self setPlaceholderString:[self stringValue]]; [self setStringValue:@""]; } - else if (_originalPlaceholderString) + else if (_originalPlaceholderString !== undefined) { // Restore the original placeholder, the actual textfield value is already correct // because it was set using setValue:forKey: [self setPlaceholderString:_originalPlaceholderString]; + _originalPlaceholderString = undefined; } _currentValueIsPlaceholder = isPlaceholder; } +- (void)unbind:(CPString)theBinding +{ + if (theBinding === CPValueBinding) + { + [self _setCurrentValueIsPlaceholder:NO]; + } + + [super unbind:theBinding]; +} + /*! For non-bezeled text fields (typically a label), sizeToFit has two behaviors, depending on the line break mode of the receiver. @@ -1270,6 +1284,8 @@ var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey", [self setAlignment:[aCoder decodeIntForKey:CPTextFieldAlignmentKey]]; [self setPlaceholderString:[aCoder decodeObjectForKey:CPTextFieldPlaceholderStringKey]]; + _originalPlaceholderString = undefined; + } diff --git a/Tests/AppKit/CPKeyValueBindingTest.j b/Tests/AppKit/CPKeyValueBindingTest.j index 6944103c6..511c1b7f2 100644 --- a/Tests/AppKit/CPKeyValueBindingTest.j +++ b/Tests/AppKit/CPKeyValueBindingTest.j @@ -222,9 +222,23 @@ [self assert:@"" equals:[textField stringValue] message:@"text field string value should be cleared"]; [self assert:@"Multiple Values" equals:[textField placeholderString] message:@"text field placeholder should be 'Multiple Values'"]; + [textField unbind:@"value"]; + [self assert:@"cheese" equals:[textField placeholderString] message:@"text field placeholder should be reset"]; + + [textField bind:@"value" toObject:arrayController withKeyPath:@"selection.cheese" options:options]; + [arrayController setSelectionIndex:0]; [self assert:@"yellow" equals:[textField stringValue] message:"text field string value should be 'yellow'"]; [self assert:@"cheese" equals:[textField placeholderString] message:"text field placeholder should be restored"]; + + textField = [[CPTextField alloc] init]; + [textField bind:@"value" toObject:arrayController withKeyPath:@"selection.cheese" options:options]; + [arrayController setSelectionIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, 2)]]; + [self assert:@"Multiple Values" equals:[textField placeholderString] message:@"text field placeholder should 'Multiple Values'"]; + + [arrayController setSelectionIndex:0]; + [self assert:@"" equals:[textField placeholderString] message:@"empty text field placeholder should be restored"]; + } - (void)observeValueForKeyPath:(CPString)aKeyPath ofObject:(id)anObject change:(CPDictionary)changes context:(id)aContext