MithrilJs - How to do radio boxes

If you ever wanted to know how to do radio boxes in mithriljs this is the way I like to do it.

by Andrew Brown

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/mithril/0.2.0/mithril.js"></script>

CSS

.val { background: rgb(250,250,250); padding: 16px; margin-bottom: 16px; }
.radio { margin-bottom: 8px; }
.radio label { margin-left: 8px; }

CoffeeScript

app =
  controller: ->
    { val: m.prop('skunk') }
  view: (ctrl)->
    fun_check = (val)->
      ->
        ctrl.val(val)
    attrs = (val)->
      onchange: m.withAttr('checked',fun_check(val))
      checked: ctrl.val() == val
    
    m '.radio_buttons',
      m '.val', ctrl.val()
      m '.radio',
        m "input[type='radio']", attrs('cat')
        m "label", 'cat'
      m '.radio',
        m "input[type='radio']", attrs('dog')
        m "label", 'dog'        
      m '.radio',
        m "input[type='radio']", attrs('skunk') 
        m "label", 'skunk'        
m.mount document.body, app