Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstraps ICheck-Helper does not trigger on changed event

Tags:

I have this Jquery code to be updating checkboxes base on whether a checkbox has been checked. However, This does not fire.

Code

$('body').on('change', '.territory', function () {
    var PK = $(this).find('input:checkbox:first').val();
    var PKStr = '.parent' + PK;
    console.log('change!');
});

$('body').on('change', '.iCheck-helper', function () {
    //var PK = $(this).find('input:checkbox:first').val();
    //var PKStr = '.parent' + PK;
    console.log('change!');
});

<div class="row">
  <div class="col-md-12 col-lg-12">
    <label class="control-label">
      Selected Territories
    </label>
  </div>

  @for (int c = 0; c < 2; ++c)
  {
     int Count = 0; 
     <div class="col-md-6 col-lg-6">
     @foreach (var ter in Infobase.MMS.Models.ComboBoxValues.GetTerritoryRights(0))
     {
        if (Count % 2 == c)
        {
          <label>
            <input type="checkbox" class="territory" value="@ter.Key">
                                                        &nbsp;@ter.Value

          </label>
        }
        Count++;
      }
   </div>
  }    
</div>

I've tried binding to the click function and change function on iCheckbox-Helper as well as directly to the checkboxes. However neither seem to work. Everything does work fine when I dont add in the Icheck.js script.

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

like image 594
johnny 5 Avatar asked Jul 10 '14 16:07

johnny 5


2 Answers

Use ifChanged or ifChecked mentioned in the documentation

$('input').on('ifChecked', function(event){
  alert(event.type + ' callback');
});
like image 54
chris Avatar answered Sep 19 '22 13:09

chris


I just added this globally and it does the trick for me.

$(".i-checks input").on('ifChanged', function (e) {
    $(this).trigger("change", e);
});
like image 30
Beakie Avatar answered Sep 20 '22 13:09

Beakie