Skip to content

Commit

Permalink
Merge pull request #167 from bitovi/issue_166
Browse files Browse the repository at this point in the history
Adding test case and fix for #166
fixes #166
  • Loading branch information
Curtis Cummings committed Nov 21, 2012
2 parents c827dec + ae0f509 commit 0e14db1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
15 changes: 15 additions & 0 deletions view/ejs/test/ejs_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,21 @@ test("live binding textarea", function(){

})

test("reset on a live bound input", function(){
var text = "<input type='text' value='<%= person.attr('name') %>'><button type='reset'>Reset</button>",
person = new can.Observe({
name: "Bob"
}),
compiled = new can.EJS({text: text}).render({person: person}),
form = document.createElement('form'),
input;

form.appendChild(can.view.frag(compiled))
input = form.getElementsByTagName('input')[0];
form.reset();
equals(input.value, "Bob", "value is correct");
});

test("A non-escaping live magic tag within a control structure and no leaks", function(){

for(var prop in can.view.nodeMap){
Expand Down
25 changes: 15 additions & 10 deletions view/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var attrMap = {
},
attributePlaceholder = '__!!__',
attributeReplace = /__!!__/g,
tagToContentPropMap= {
tagToContentPropMap = {
option: "textContent",
textarea: "value"
},
Expand All @@ -40,15 +40,20 @@ var attrMap = {
getParentNode = function(el, defaultParentNode){
return defaultParentNode && el.parentNode.nodeType === 11 ? defaultParentNode : el.parentNode;
},
setAttr = function(el, attrName, val){
// if this is a special property
if ( attrMap[attrName] ) {
// set the value as true / false
el[attrMap[attrName]] = can.inArray(attrName,bool) > -1 ? true : val;
} else {
el.setAttribute(attrName, val);
}
},
setAttr = function (el, attrName, val) {
var tagName = el.nodeName.toString().toLowerCase(),
prop = attrMap[attrName];
// if this is a special property
if (prop) {
// set the value as true / false
el[prop] = can.inArray(attrName, bool) > -1 ? true : val;
if(prop === "value" && tagName === "input") {
el.defaultValue = val;
}
} else {
el.setAttribute(attrName, val);
}
},
getAttr = function(el, attrName){
// Default to a blank string for IE7/8
return (attrMap[attrName]?
Expand Down

0 comments on commit 0e14db1

Please sign in to comment.