From 3685b15fd8be66f37a7b7e35eb08b359bb160cfa Mon Sep 17 00:00:00 2001 From: Nick Takayama Date: Fri, 10 Oct 2008 22:17:45 +0800 Subject: [PATCH] making the placeholderText functional Signed-off-by: Nick Takayama --- AppKit/CPTextField.j | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-) diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index 3bcd293..9009ab1 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -309,11 +309,11 @@ var _CPTextFieldSquareBezelColor = nil; [[self window] makeFirstResponder:nil]; } }; - - // If current value is the placeholder value, remove it to allow user to update. - if ([_value lowercaseString] == [[self placeholderString] lowercaseString]) - [self setStringValue:@""]; + // If current value is the placeholder value, remove it to allow user to update. + if ([string lowercaseString] == [[self placeholderString] lowercaseString]) + [self setStringValue:@""]; + [[CPDOMWindowBridge sharedDOMWindowBridge] _propagateCurrentDOMEvent:YES]; #endif @@ -442,6 +442,10 @@ var _CPTextFieldSquareBezelColor = nil; return [[self class] _inputElement].value; #endif + //if the content is the same as the placeholder value, return "" instead + if ([_value lowercaseString] == [[self placeholderString] lowercaseString]) + return ""; + return [super stringValue]; } @@ -462,13 +466,11 @@ var _CPTextFieldSquareBezelColor = nil; if ([[self window] firstResponder] == self) [[self class] _inputElement].value = displayString; - else - { - if (CPFeatureIsCompatible(CPJavascriptInnerTextFeature)) - _DOMTextElement.innerText = displayString; - else if (CPFeatureIsCompatible(CPJavascriptTextContentFeature)) - _DOMTextElement.textContent = displayString; - } + + if (CPFeatureIsCompatible(CPJavascriptInnerTextFeature)) + _DOMTextElement.innerText = displayString; + else if (CPFeatureIsCompatible(CPJavascriptTextContentFeature)) + _DOMTextElement.textContent = displayString; #endif } @@ -487,6 +489,10 @@ var _CPTextFieldSquareBezelColor = nil; -(void)setPlaceholderString:(CPString)aStringValue { _placeholderString = aStringValue; + + //if there is no set value, automatically display the placeholder + if (!_value) + [self setStringValue:aStringValue]; } /* -- 1.5.4.5