Bootstraps ICheck-Helper does not start when event changes

I have jQuery code to update checkboxes on checkbox checkbox checkbox. However, this does not work.

the 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 tried to snap the click function and change the function to iCheckbox-Helper, as well as directly to the checkboxes. However, it does not seem to work. Everything works fine when I don't add a script to Icheck.js.

Does anyone know how to connect to a modified event from the Icheckhelper bootstrap class?

+4
source share
3 answers

Use ifChanged or ifChecked mentioned in the documentation

$('input').on('ifChecked', function(event){
  alert(event.type + ' callback');
});
+16
source

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

$(".i-checks input").on('ifChanged', function (e) {
    $(this).trigger("change", e);
});
+6

jQuery onClick

$('input[type="checkbox"], input[type="radio"]').on('ifChanged', function (e) {
     $(this).trigger("onclick", e);
});
+2

Source: https://habr.com/ru/post/1547950/


All Articles