Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Render a checkbox as unchecked when the given value is false.

  • Loading branch information...
commit b74477fa3f2b4bf680d67717cf32c58031dd2786 1 parent 2e504bd
Chris Nelson authored
View
25 example/spec/javascripts/views/check_box_view_spec.coffee
@@ -1,18 +1,27 @@
describe "check box view", ->
beforeEach ->
setFixtures "<div id='check_box_view'></div>"
- @model = new Example.Models.Thing(awesome: true)
+ @model = new Example.Models.Thing
@checkBoxFieldView = new Backtastic.Views.CheckBoxView
model: @model
field: "awesome"
label: "Awesome"
el: $("#check_box_view")
parentView: new Example.Views.FormView
- @checkBoxFieldView.render()
-
- it "renders a check box input", ->
- expect(@checkBoxFieldView.$("input[type=checkbox]")).toExist()
-
- it "renders a checked check box if the value is true", ->
- expect(@checkBoxFieldView.$("input[type=checkbox]").attr("checked")).toEqual("checked")
+ describe "when the value is true", ->
+ beforeEach ->
+ @model.set awesome: true
+ @checkBoxFieldView.render()
+ it "renders a check box input", ->
+ expect(@checkBoxFieldView.$("input[type=checkbox]")).toExist()
+ it "renders a checked check box if the value is true", ->
+ expect(@checkBoxFieldView.$("input[type=checkbox]").attr("checked")).toEqual("checked")
+
+ describe "when value is false", ->
+ beforeEach ->
+ @model.set awesome: false
+ @checkBoxFieldView.render()
+ it "render an unchecked check box if the value is false", ->
+ expect(@checkBoxFieldView.$("input[type=checkbox]").attr("checked")).toBeFalsy()
+
View
2  lib/assets/javascripts/views/check_box_view.coffee
@@ -5,4 +5,4 @@ class Backtastic.Views.CheckBoxView extends Backtastic.Views.FormFieldView
render: ->
super
- @$('input').prop("checked", "checked")
+ @$('input').prop("checked", "checked") if @model.get(@field)
Please sign in to comment.
Something went wrong with that request. Please try again.