Skip to content

Commit

Permalink
Merge pull request #1907 from bitovi/fix/1790/cast-attr-to-string
Browse files Browse the repository at this point in the history
Fixes #1790. Cast element.getAttrs to string in live.js
  • Loading branch information
daffl committed Sep 11, 2015
2 parents a9238a8 + 72b5fd3 commit eab18ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion view/live/live.js
Expand Up @@ -595,7 +595,8 @@ steal('can/util', 'can/view/elements.js', 'can/view', 'can/view/node_lists', 'ca
can.data(wrapped, 'hooks', hooks = {});
}
// Get the attribute value.
var attr = elements.getAttr(el, attributeName),
// Cast to String. String expected for rendering. Attr may return other types for some attributes.
var attr = String(elements.getAttr(el, attributeName)),
// Split the attribute value by the template.
// Only split out the first __!!__ so if we have multiple hookups in the same attribute,
// they will be put in the right spot on first render
Expand Down
14 changes: 11 additions & 3 deletions view/live/live_test.js
Expand Up @@ -220,7 +220,15 @@ steal("can/view/live", "can/observe", "can/test", "steal-qunit", function () {


});




test("can.live.attribute works with non-string attributes (#1790)", function() {
var el = document.createElement('div'),
compute = can.compute(function() {
return 2;
});

can.view.elements.setAttr(el, "value", 1);
can.view.live.attribute(el, 'value', compute);
ok(true, 'No exception thrown.');
});
});

0 comments on commit eab18ac

Please sign in to comment.