From edde70d4f5a73f5231d8d390477558684b2045bc Mon Sep 17 00:00:00 2001 From: Jonathan Otto Date: Wed, 10 Aug 2011 16:38:23 -0500 Subject: [PATCH 1/2] update rails v to latest --- backbone-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backbone-rails.gemspec b/backbone-rails.gemspec index e79cecf..8bf84e0 100644 --- a/backbone-rails.gemspec +++ b/backbone-rails.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.description = "Quickly setup backbone.js for use with rails 3.1. Generators are provided to quickly get started." s.files = Dir["lib/**/*"] + Dir["vendor/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"] - s.add_dependency('rails', '~> 3.1.0.rc5') + s.add_dependency('rails', '~> 3.0.10.rc1') s.add_dependency('coffee-script', '~> 2.2.0') s.add_dependency('ejs', '~> 1.0.0') From 289516be72f7558c87901b6614b4dde27b5beece Mon Sep 17 00:00:00 2001 From: Jonathan Otto Date: Sun, 21 Aug 2011 18:25:37 -0500 Subject: [PATCH 2/2] this includes the checkbox prop changes from my last pull request, and adds a check to ensure there's a value on the name attribute of an element before binding to an event (otherwise any input without a name attr will bind to change:undefined). another way of handling this might be using $(":input[name]") instead of $(":input"). either way. --- .../assets/javascripts/backbone_datalink.js | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/vendor/assets/javascripts/backbone_datalink.js b/vendor/assets/javascripts/backbone_datalink.js index 15683c6..b3458d9 100644 --- a/vendor/assets/javascripts/backbone_datalink.js +++ b/vendor/assets/javascripts/backbone_datalink.js @@ -5,17 +5,28 @@ var el, name; el = $(this); name = el.attr("name"); - model.bind("change:" + name, function() { - return el.val(model.get(name)); - }); - return $(this).bind("change", function() { - var attrs; - el = $(this); - attrs = {}; - attrs[el.attr("name")] = el.val(); - return model.set(attrs); - }); + + if(typeof name !== "undefined" && name !== null) { + model.bind("change:" + name, function() { + val = model.get(name) + if ( el.is("input[type='checkbox']") && (val == true || val == false) ) + el.prop('checked', val); + return el.val(val); + }); + + return $(this).bind("change", function() { + var attrs; + el = $(this); + attrs = {}; + if ( el.is("input[type='checkbox']") ) + attrs[el.attr("name")] = el.prop('checked'); + else + attrs[el.attr("name")] = el.val(); + return model.set(attrs); + }); + } + }); } }); -})(jQuery); +})(jQuery); \ No newline at end of file