Skip to content

Commit

Permalink
Merge pull request #10550 from rwjblue/ensure-that-attrs-are-written-…
Browse files Browse the repository at this point in the history
…at-least-once

[BUGFIX beta] Ensure that AttrNode's for value are rendered at least once.
  • Loading branch information
rwjblue committed Feb 28, 2015
2 parents f3a6b40 + fee7e5e commit 673e202
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/ember-htmlbars/tests/attr_nodes/value_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,17 @@ QUnit.test("string property is output", function() {
'property is set true');
});

QUnit.test("blank property is output", function() {
view = EmberView.create({
context: { name: '' },
template: compile("<input value={{name}}>")
});
appendView(view);

equal(view.element.firstChild.tagName, 'INPUT', "input element is created");
equal(view.element.firstChild.value, "",
'property is set true');
});

// jscs:enable validateIndentation
}
4 changes: 3 additions & 1 deletion packages/ember-views/lib/attr_nodes/attr_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ AttrNode.prototype.init = function init(attrName, simpleAttrValue) {
this.isDirty = true;
this.isDestroying = false;
this.lastValue = null;
this.hasRenderedInitially = false;

subscribe(this.attrValue, this.rerender, this);
};
Expand Down Expand Up @@ -52,14 +53,15 @@ AttrNode.prototype.render = function render(buffer) {
}

// If user is typing in a value we don't want to rerender and loose cursor position.
if (this.attrName === 'value' && this._morph.element.value === value) {
if (this.hasRenderedInitially && this.attrName === 'value' && this._morph.element.value === value) {
this.lastValue = value;
return;
}

if (this.lastValue !== null || value !== null) {
this._morph.setContent(value);
this.lastValue = value;
this.hasRenderedInitially = true;
}
};

Expand Down

0 comments on commit 673e202

Please sign in to comment.