Skip to content

Commit

Permalink
Merge pull request #10398 from mixonic/undefined-is-null
Browse files Browse the repository at this point in the history
[BUGFIX release] undefined and values in bind-attr shoud remove attributes
  • Loading branch information
rwjblue committed Feb 9, 2015
2 parents 20b46aa + b01b816 commit 8bbd490
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
26 changes: 26 additions & 0 deletions packages/ember-htmlbars/tests/helpers/bind_attr_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,29 @@ QUnit.test("asserts for <div data-bar='foo' {{bind-attr data-bar='blah'}}></div>
runAppend(view);
}, /You cannot set `data-bar` manually and via `{{bind-attr}}` helper on the same element/);
});

QUnit.test("src attribute bound to undefined is not present", function() {
var template = compile("<img {{bind-attr src=view.undefinedValue}}>");

view = EmberView.create({
template: template,
undefinedValue: undefined
});

runAppend(view);

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

QUnit.test("src attribute bound to null is not present", function() {
var template = compile("<img {{bind-attr src=view.nullValue}}>");

view = EmberView.create({
template: template,
nullValue: null
});

runAppend(view);

ok(!view.element.hasAttribute('src'), "src attribute not present");
});
6 changes: 5 additions & 1 deletion packages/ember-views/lib/attr_nodes/legacy_bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ LegacyBindAttrNode.prototype.render = function render(buffer) {
}
var value = read(this.attrValue);

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

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

Expand Down

0 comments on commit 8bbd490

Please sign in to comment.