Radio buttons and behavior work, but when translating working radio buttons to icheck plug in, I can't figure out one easy line

StackOverflow https://stackoverflow.com/questions/18685487

Here is the coffee script that effects the behavior on radio buttons. Example can be found here: http://jsfiddle.net/ambiguous/Xk5ZC/

$(document).on 'change', '.stepRadio', ->
      $container = $(@).closest('.stepCreator')
      $container.find(".excelCreator, .videoCreator, .mcCreator").hide()
      if @value is "video"
        $container.find(".videoCreator").show()
      else if @value is "excel"
        $container.find(".excelCreator").show()
      else if @value is "multiple_choice"
        $container.find(".mcCreator").show()
    # This initializes things. Since I have `:checked => true`
    # on the first radio button, `:checked` will always match one
    # radio button.
    $('.stepRadio:checked').change()

Here is an attempt to translate the above to iCheck. However, I have problems on the last line of the code, in which I am trying to initalize the coffeescript.

 $(document).on 'ifChecked', '.stepRadio', ->
    $container = $(@).closest('.stepCreator')
    $container.find(".excelCreator, .videoCreator, .mcCreator").hide()
    if @value is "video"
      $container.find(".videoCreator").show()
    else if @value is "excel"
      $container.find(".excelCreator").show()
    else if @value is "multiple_choice"
      $container.find(".mcCreator").show()
# This does not initialize things, as it should:
 $('.stepRadio:checked').ifChecked()

I tried a couple of other things to initialize the code as well, such as

$('.stepRadio:checked').iCheck('check')

Nothing has worked.

Any help would be appreciated. Here is icheck: https://github.com/fronteed/iCheck

有帮助吗?

解决方案

The last line I was looking for was :

$('.stepRadio:checked').trigger('ifChecked')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top