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] Undefined should not set an attribute. #10687

Merged
merged 1 commit into from
Mar 22, 2015
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
4 changes: 2 additions & 2 deletions packages/ember-htmlbars/tests/helpers/bind_attr_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ QUnit.test("src attribute bound to undefined is not present", function() {

runAppend(view);

ok(!view.element.hasAttribute('src'), "src attribute not present");
ok(!view.element.firstChild.hasAttribute('src'), "src attribute not present");
});

QUnit.test("src attribute bound to null is not present", function() {
Expand All @@ -597,7 +597,7 @@ QUnit.test("src attribute bound to null is not present", function() {

runAppend(view);

ok(!view.element.hasAttribute('src'), "src attribute not present");
ok(!view.element.firstChild.hasAttribute('src'), "src attribute not present");
});

QUnit.test('specifying `<div {{bind-attr style=userValue}}></div>` is [DEPRECATED]', function() {
Expand Down
38 changes: 38 additions & 0 deletions packages/ember-htmlbars/tests/helpers/input_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,41 @@ QUnit.test("checkbox name is updated", function() {
QUnit.test("checkbox checked property is updated", function() {
equal(view.$('input').prop('checked'), false, "the checkbox isn't checked yet");
});

QUnit.module("{{input type='text'}} - null/undefined values", {
teardown() {
runDestroy(view);
}
});

QUnit.test("placeholder attribute bound to undefined is not present", function() {
view = View.extend({
controller: {},
template: compile('{{input placeholder=someThingNotThere}}')
}).create();

runAppend(view);

ok(!view.element.childNodes[1].hasAttribute('placeholder'), "attribute not present");

run(null, set, view, 'controller.someThingNotThere', 'foo');

equal(view.element.childNodes[1].placeholder, 'foo', "attribute is present");
});

QUnit.test("placeholder attribute bound to null is not present", function() {
view = View.extend({
controller: {
someNullProperty: null
},
template: compile('{{input placeholder=someNullProperty}}')
}).create();

runAppend(view);

ok(!view.element.childNodes[1].hasAttribute('placeholder'), "attribute not present");

run(null, set, view, 'controller.someNullProperty', 'foo');

equal(view.element.childNodes[1].placeholder, 'foo', "attribute is present");
});
6 changes: 6 additions & 0 deletions packages/ember-views/lib/attr_nodes/attr_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ AttrNode.prototype.render = function render(buffer) {
if (this.isDestroying) {
return;
}

var value = read(this.attrValue);

if (this.attrName === 'value' && (value === null || value === undefined)) {
value = '';
}

if (value === undefined) {
value = null;
}


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