Permalink
Browse files

fixed datalink binding for checkboxes

  • Loading branch information...
1 parent e621ffb commit b8676a50ee22eb68e34fdd13935dd427e1f2ad98 @minhajuddin committed Oct 24, 2011
Showing with 9 additions and 3 deletions.
  1. +9 −3 vendor/assets/javascripts/backbone_datalink.js
@@ -6,13 +6,19 @@
el = $(this);
name = el.attr("name");
model.bind("change:" + name, function() {
- return el.val(model.get(name));
+ if(el.is(":checkbox")){
+ return el.attr("checked", !!model.get(name));
+ }
+ else{
+ return el.val(model.get(name));
+ }
});
return $(this).bind("change", function() {
- var attrs;
+ var attrs, newValue;
el = $(this);
attrs = {};
- attrs[el.attr("name")] = el.val();
+ newValue = el.is(":checkbox") ? el.is(":checked") : el.val();
+ attrs[el.attr("name")] = newValue;
return model.set(attrs);
});
});

0 comments on commit b8676a5

Please sign in to comment.