Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Ensure that AttrNode's for value are rendered at least once. #10550

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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