mikeric/rivets — pull request #143 by kayhadrin (2013-04-05 16:54:34+00:00)
Title: Improve radio box binders

Hi there,

I'm submitting this pull request because I believe that the checked and unchecked binders should be improved.

* __Improve comparison code__
Currently, the algorithm to compare the radio input value to the data model value does a fully typed comparison (in js)
e.g. `el.checked = el.value === value`
Considering that radio input values are always strings, this won't work with when the model value is a boolean.
So my suggested solution is to cast the model value to string by default.

```coffeescript
checked:
publishes: true
bind: (el) ->
@currentListener = bindEvent el, 'change', @publish
unbind: (el) ->
unbindEvent el, 'change', @currentListener
routine: (el, value) ->
if el.type is 'radio'
# it was: el.checked = el.value is value
el.checked = el.value?.toString() is value?.toString()
else
el.checked = !!value

unchecked:
publishes: true
bind: (el) ->
@currentListener = bindEvent el, 'change', @publish
unbind: (el) ->
unbindEvent el, 'change', @currentListener
routine: (el, value) ->
if el.type is 'radio'
# it was: el.checked = el.value isnt value
el.checked = el.value?.toString() isnt value?.toString()
else
el.checked = !value
```

Note that I've only changed this code for radio inputs.
Based on that, for the "checked" binder, a radio box will be checked only if the input value is equal to the model value (after coercing it to a string).

* __Improve jasmine test case__
The jasmine test cases for the checked/unchecked binders were incorrectly using a DIV element as test target so the results were not relevant.
So I've changed them using radio input boxes and checkboxes.

I hope this helps.

Feel free to let me know if there's any issues.

Regards,

David