Permalink
Browse files

Merge pull request #591 from jmulieri/master

Resolving Issue #590, 'Hint not working properly for SC.TextFieldView in IE'
  • Loading branch information...
2 parents ceaeda4 + b3bb40f commit c5662c12da98bd7011dd1c887a9e08754a9baa66 Colin Campbell committed Sep 27, 2011
Showing with 19 additions and 2 deletions.
  1. +15 −0 frameworks/foundation/tests/views/text_field/ui.js
  2. +4 −2 frameworks/foundation/views/text_field.js
View
15 frameworks/foundation/tests/views/text_field/ui.js
@@ -623,6 +623,21 @@ test("focus and blurring text field", function() {
});
+test("focus and blur an empty text field", function() {
+ var view = pane.view('empty');
+ var input = view.$('input');
+
+ // verify the field is empty and the hint is properly set
+ pane.verifyEmpty(view, 'Full Name');
+
+ // focus and blur the text field
+ SC.Event.trigger(input, 'focus');
+ SC.Event.trigger(input, 'blur');
+
+ // field should still be still be empty with hint properly set
+ pane.verifyEmpty(view, 'Full Name');
+});
+
test("editing a field should not change the cursor position", function() {
var textField = pane.view('empty');
var input = textField.$('input');
View
6 frameworks/foundation/views/text_field.js
@@ -602,6 +602,7 @@ SC.TextFieldView = SC.FieldView.extend(SC.StaticLayout, SC.Editable,
if (!SC.platform.input.placeholder) {
context.setClass('sc-hint', YES);
+ input.val(hint);
}
} else {
// Internet Explorer doesn't allow you to modify the type afterwards
@@ -771,7 +772,7 @@ SC.TextFieldView = SC.FieldView.extend(SC.StaticLayout, SC.Editable,
this.set('focused',YES);
this.fieldDidFocus(evt);
var val = this.get('value');
- if(!SC.platform.input.placeholder && ((!val) || (val && val.length===0))) {
+ if(!SC.platform.input.placeholder && ((!val) || (val && val.length===0) || (val && val == this.hint))) {
this._hintON = NO;
}
}, this);
@@ -790,8 +791,9 @@ SC.TextFieldView = SC.FieldView.extend(SC.StaticLayout, SC.Editable,
this.fieldDidBlur(this._origEvent || evt);
var val = this.get('value');
- if(!SC.platform.input.placeholder && ((!val) || (val && val.length===0))) {
+ if(!SC.platform.input.placeholder && !this._hintON && ((!val) || (val && val.length===0))) {
this._hintON = YES;
+ this.updateLayer();
}
}, this);
},

0 comments on commit c5662c1

Please sign in to comment.