Permalink
Browse files

added radio input writer

  • Loading branch information...
1 parent 3b75f63 commit 4864f30a8c46696568eb9e9d02d8525f53b64cf3 @scttnlsn scttnlsn committed May 29, 2012
Showing with 10 additions and 10 deletions.
  1. +1 −8 spec/javascripts/deserialize.spec.js
  2. +9 −2 src/backbone.syphon.inputwriters.js
View
9 spec/javascripts/deserialize.spec.js
@@ -192,16 +192,9 @@ describe("deserializing an object into a form", function(){
Backbone.Syphon.deserialize(view, { foo: "bar" });
});
-
- it("should set the input's value to the corresponding value in the given object", function(){
- var result = view.$("input[name=foo]").val();
- expect(result).toBe("bar");
- });
it("should select the corresponding radio button", function(){
- var value = view.$("input[name=foo]").val();
- var checked = view.$("input[name=foo][value=" + value + "]").prop("checked");
-
+ var checked = view.$("input[name=foo][value=bar]").prop("checked");
expect(checked).toBe(true);
});
});
View
11 src/backbone.syphon.inputwriters.js
@@ -14,8 +14,15 @@ Backbone.Syphon.InputWriters.registerDefault(function($el, value){
$el.val(value);
});
-// Checkbox writer, returning a boolean value for
-// whether or not the checkbox is checked.
+// Checkbox writer, set whether or not the checkbox is checked
+// depending on the boolean value.
Backbone.Syphon.InputWriters.register("checkbox", function($el, value){
$el.prop("checked", value);
});
+
+// Radio button writer, set whether or not the radio button is
+// checked. The button should only be checked if it's value
+// equals the given value.
+Backbone.Syphon.InputWriters.register("radio", function($el, value){
+ $el.prop("checked", $el.val() === value);
+});

0 comments on commit 4864f30

Please sign in to comment.