Bootstrap ICheck can not listen changed event

284 Views Asked by At

I have this jQuery code to be updating radios base on whether a radios has been checked. However, this does not fire.

Code

    this.init = function() {
    $.ajax({
        "url": "/cms/api/task_management/init",
        "contentType": "application/json",
        "dataType": "json",
        "type": "POST"
    }).done(function(map) {
        if ($("#title").val() || $("#problemCls").val() || $("#targetFunc").val() || $("#status").val() || $("#priority").val()) {
            search();
        } else {
            callBackInit(map);
        }
    }).fail(failCallback);
    $("input[type='radio']").on("ifChanged", function (event) {
        if ($("#display-method-unique").prop("checked")) {
            renderDataTable(self.taskManagementList);
        } else {
            renderDataTable(self.allDataList);
        }
    }).iCheck({
        radioClass: 'iradio_flat-green'
    });

HTML

<div class="row">
     <div class="col-md-4 col-sm-12 col-xs-12">
          <div class="radio">
               <input type="radio" name="display-method" id="display-method-unique" class="flat"><label for="display-method-unique">Doing</label>
               <input type="radio" name="display-method" id="display-method-all" class="flat"><label for="display-method-all">End</label>
           </div>
    </div>
</div>

I've also tried binding to the click function and change function. But the change event can't be listened. However neither seem to work. Everything does work fine when I don't add in the Icheck.js script.

Does anybody know how to hook into on changed event from bootstraps Icheckhelper class?

1

There are 1 best solutions below

0
On BEST ANSWER

I found useful fix as has been correctly answered from github forum :read from this thread and How to handle radio event when iCheck-helper is used?

Then I changed my code. The problem has be solved.

$("input[name='display-method']").iCheck({radioClass: 'iradio_flat-green'});

this.init = function() {
    $.ajax({
        "url": "/cms/api/task_management/init",
        "contentType": "application/json",
        "dataType": "json",
        "type": "POST"
    }).done(function(map) {
        if ($("#title").val() || $("#problemCls").val() || $("#targetFunc").val() || $("#status").val() || $("#priority").val()) {
            search();
        } else {
            callBackInit(map);
        }
        $("input[name='display-method']").on("ifCreated ifClicked ifChanged ifChecked ifUnchecked ifDisabled ifEnabled ifDestroyed check", function (event) {
            if ($("#display-method-unique").prop("checked")) {
                renderDataTable(self.taskManagementList);
            } else {
                renderDataTable(self.allDataList);
            }
        });
    }).fail(failCallback);
};