Skip to content

Commit

Permalink
Merge pull request #10709 from dgeb/bug-fix-10675
Browse files Browse the repository at this point in the history
[BUGFIX beta] Remove attributes that are set to `null` or `undefined`.
  • Loading branch information
rwjblue committed Mar 24, 2015
2 parents ad35fd6 + 7a60940 commit 4cd4c7c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
45 changes: 41 additions & 4 deletions packages/ember-htmlbars/tests/helpers/bind_attr_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ QUnit.test("asserts for <div data-bar='foo' {{bind-attr data-bar='blah'}}></div>
}, /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() {
QUnit.test("src attribute bound to undefined is empty", function() {
var template = compile("<img {{bind-attr src=view.undefinedValue}}>");

view = EmberView.create({
Expand All @@ -584,10 +584,10 @@ QUnit.test("src attribute bound to undefined is not present", function() {

runAppend(view);

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

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

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

runAppend(view);

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

QUnit.test("src attribute will be cleared when the value is set to null or undefined", function() {
var template = compile("<img {{bind-attr src=view.value}}>");

view = EmberView.create({
template: template,
value: 'one'
});

runAppend(view);

equal(view.element.firstChild.getAttribute('src'), 'one', "src attribute is present");

run(function() {
set(view, 'value', 'two');
});

equal(view.element.firstChild.getAttribute('src'), 'two', "src attribute is present");

run(function() {
set(view, 'value', null);
});

equal(view.element.firstChild.getAttribute('src'), '', "src attribute is empty");

run(function() {
set(view, 'value', 'three');
});

equal(view.element.firstChild.getAttribute('src'), 'three', "src attribute is present");

run(function() {
set(view, 'value', undefined);
});

equal(view.element.firstChild.getAttribute('src'), '', "src attribute is empty");
});

QUnit.test('specifying `<div {{bind-attr style=userValue}}></div>` is [DEPRECATED]', function() {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-views/lib/attr_nodes/legacy_bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ LegacyBindAttrNode.prototype.render = function render(buffer) {
value = null;
}

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

Expand Down

0 comments on commit 4cd4c7c

Please sign in to comment.