Skip to content

Commit

Permalink
Merge pull request canjs#580 from simpleTechs/can-value-no-undefined
Browse files Browse the repository at this point in the history
can-value shows "undefined" if bound to undefined value
  • Loading branch information
daffl committed Dec 3, 2013
2 parents 3c4c637 + fdd650c commit fb0fca6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion view/bindings/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ steal("can/util","can/view/mustache", "can/control", function(can){
},
"{value} change": "set",
set: function(){
this.element[0].value = this.options.value()
var val = this.options.value();
this.element[0].value = (typeof val === 'undefined' ? '' : val);
},
"change": function(){
this.options.value(this.element[0].value)
Expand Down
8 changes: 6 additions & 2 deletions view/bindings/bindings_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

var template = can.view.mustache("<input can-value='age'/>")

var map = new can.Map({age: "30"})
var map = new can.Map()

var frag = template( map )

Expand All @@ -52,7 +52,11 @@
ta.appendChild(frag);

var input = ta.getElementsByTagName("input")[0];
equal(input.value, "30", "input value set correctly")
equal(input.value, "", "input value set correctly if key does not exist in map");

map.attr("age", "30");

equal(input.value, "30", "input value set correctly");

map.attr("age","31");

Expand Down

0 comments on commit fb0fca6

Please sign in to comment.