Permalink
Browse files

fix #288 placeholder not removed correctly after data model changes

  • Loading branch information...
1 parent c05e6de commit b91b822707d10730e0d58ade82ca53b7b95e7faf @flongo committed Dec 19, 2012
Showing with 26 additions and 7 deletions.
  1. +21 −6 src/aria/html/TextInput.js
  2. +5 −1 test/aria/html/textinput/placeholder/PlaceholderTestCase.js
View
@@ -69,11 +69,7 @@
var specialKeys = [domevent.KC_END, domevent.KC_RIGHT, domevent.KC_ARROW_RIGHT, domevent.KC_DOWN,
domevent.KC_ARROW_DOWN, domevent.KC_DELETE, domevent.KC_BACKSPACE];
if (!aria.utils.Array.contains(specialKeys, event.keyCode)) {
- var cssClass = new aria.utils.ClassList(this._domElt);
- this._domElt.value = "";
- this._hasPlaceholder = false;
- cssClass.remove('placeholder');
- cssClass.$dispose();
+ this._removePlaceholder();
} else {
event.preventDefault();
}
@@ -255,7 +251,11 @@
*/
onbind : function (name, value, oldValue) {
if (name === "value") {
- this._domElt.value = (value != null) ? value : "";
+ value = (value != null) ? value + "" : "";
+ if (value) {
+ this._removePlaceholder()
+ }
+ this._domElt.value = value;
this._setPlaceholder();
}
},
@@ -339,6 +339,21 @@
},
/**
+ * Remove the css class and value for placeholder if needed by browsers that don't support it natively.
+ * @protected
+ */
+ _removePlaceholder : function () {
+ if (this._hasPlaceholder) {
+ var element = this._domElt;
+ var cssClass = new aria.utils.ClassList(element);
+ element.value = "";
+ this._hasPlaceholder = false;
+ cssClass.remove('placeholder');
+ cssClass.$dispose();
+ }
+ },
+
+ /**
* Add special listeners on top of the ones specified in configuration.
* @param {aria.html.beans.TextInputCfg.Properties} cfg Widget configuration.
* @param {aria.templates.TemplateCtxt} context Template context.
@@ -209,10 +209,14 @@ Aria.classDefinition({
},
_testWhenDataChangeToNull : function () {
- aria.utils.Json.setValue(this.data, "arrival", "");
+ aria.utils.Json.setValue(this.data, "arrival", null);
this.assertEquals(this.thirdElement.value, "Set arrival", "The placeholder is not displayed after nullifying the datamodel to which the widget is bound");
this.assertTrue(this.cssClass3.contains("placeholder"), "Css class placeholder is not there");
+ aria.utils.Json.setValue(this.data, "arrival", "fake");
+ this.assertEquals(this.thirdElement.value, "fake", "The placeholder has not been removed");
+ this.assertFalse(this.cssClass3.contains("placeholder"), "Css class placeholder is not removed properly after bound data changes");
+
this.end();
}

0 comments on commit b91b822

Please sign in to comment.