drgullin / icheck

Highly customizable checkboxes and radio buttons (jQuery & Zepto)
http://fronteed.com/iCheck
7.38k stars 1.62k forks source link

icheck checkboxes do not fire change events when toggled? #244

Closed brocatus closed 3 years ago

brocatus commented 9 years ago

I have a handler for the change event on a checkbox input. When icheck is applied to that checkbox the handler is not called when clicking the checkbox. I also note that the state (checked) is not transferred / registered at the input level, only at the enclosing div. Can check be used with jQuery handlers on the regular checkbox events?

nikpachoo commented 9 years ago

+1. It's really strange that a native event is not called.

ronnyandre commented 9 years ago

+1

felipepodesta commented 9 years ago

+1

ivantcholakov commented 9 years ago

+1

ianvink commented 9 years ago

+1

davidjahns commented 9 years ago

+1

AndrewEastwood commented 9 years ago

+1 it's must be high priority to be fixed because that's core event and many libs are watching that change event

AndrewEastwood commented 9 years ago

hey @fronteed , do you still maintain the project?

AndrewEastwood commented 9 years ago

and, to temporary bypass this problem:

$('input').on('ifChanged', function (event) { $(event.target).trigger('change'); });

:grinning:

gtrias commented 9 years ago

+1

martijndwars commented 9 years ago

+1

mnoble01 commented 9 years ago

+1

This code worked to trigger the native events in Chrome: $('input').on('ifClicked', function (ev) { $(ev.target).click() })

But this same code did nothing in Firefox.

@AndrewEastwood's ifChanged code worked in both.

mayurmehta commented 9 years ago

You can use

// For oncheck callback $('#checkbox_id').on('ifChecked', function () { //Do your code })

// For onUncheck callback $('#checkbox_id').on('ifUnchecked', function () { //Do your code })

It's working for me. Thanks

abdulkholid commented 8 years ago

I use this. It works. $('input').on('ifChecked', function(event){ alert(event.type + ' callback'); });

I got this from here : http://icheck.fronteed.com/

camohub commented 7 years ago

This is insane! That has to bee the first sentence in documentation. Plugin does not trigger native onchange event. WTH?

tziporaziegler commented 7 years ago

@AndrewEastwood's solution for some reason didn't work for me. I instead used the following code as a workaround to this issue:

$("input[type='checkbox']").on('ifChanged', function (e) {
    $(this).val(e.target.checked == true);
});
Praneshjs commented 7 years ago

This is not my own code, but i am using it, it works fine function pageLoad(sender, args) { $(document).ready(function () { $('.iCheck-helper').on('click', function (event) { var mapper = $(this).siblings().find('input[type=radio]'); $('#' + $(mapper.prevObject).attr('id')).trigger("click"); }); }); }

grammophone commented 7 years ago

This is what i do to remedy the situation transparently, ie to fire the changed event as required by the standard and the frameworks that expect it:

var checkboxes = $("#myForm").find(".icheck input[type=checkbox]");

checkboxes.on('ifChecked ifUnchecked', function (event) {
  $(event.target).change();
});
hanetooth commented 7 years ago

+1

jimigrunge commented 7 years ago

+1 Is this project even supported anymore?

iamsolarplexus commented 7 years ago

No, I don't think so. Check out uniform.js. It seems to have more recent life and will support hundreds of elements per page.

mostafiz57 commented 6 years ago

Working for me $('.i-checks').iCheck({ checkboxClass: 'icheckbox_square-green', radioClass: 'iradio_square-green', }).on('ifChanged', function(e) { // Get the field name var isChecked = e.currentTarget.checked;

if (isChecked == true) {

}

});

nathanjosiah commented 6 years ago

@mostafiz57 Yes it works (mostly) but the issue with that as well the proprietary events is that now my codebase is tied to a plugin with no way to naturally abstract it. For a comparable example, I can swap out my select2 implementation at any time and virtually none of my code has to change. Also, any other devs that work on the code don't have to know or learn any custom events or handling like what has to be done here.

holyfalcon commented 6 years ago

@mayurmehta realy realy thank you. that's work. I wish I'd seen your comment earlier.

fdivrusa commented 6 years ago

+1

Juuuke commented 6 years ago

+1

pitchart commented 6 years ago

+1

horror commented 6 years ago

+1

alejandroortiz1961 commented 6 years ago

I fixed this issue by applying the element class used to initialize iCheck to EACH INDIVIDUAL CHECKBOX input, not just to the containing div. Works perfectly now. Hope this helps someone else.

webmastervishal commented 6 years ago

This solution is working fine in jQuery, but I am using it in React JS project, native event isn't fired

Inside jquery file

$("#testcheckbox").on('ifChecked', function(e) {
    $(e.target).trigger('change');
});

Inside React Component <input type="checkbox" id="testcheckbox" className="icheck" onChange={this.handleCheckBoxChange} />

2gen commented 6 years ago

I used: $(".i-checks").on('ifToggled', function(e) { $(e.target).trigger('change'); }); If you use "ifChecked" that'll only trigger the change event when the checkbox is checked. But not when it is unchecked. ifToggled does both.

nhantam commented 6 years ago
$('#input[type="radio"].minimal').on('ifChecked', function(event){
    var service_type = event.target.value;
    // code your control
});
mwinamu commented 6 years ago

+1

tripflex commented 4 years ago

In my situation the checkboxes were wrapped inside another div that had a class that started with icheckbox_ so I adapted @grammophone code:

/**
 * Fix for iCheck lib not triggering change event
 * @see https://github.com/fronteed/icheck/issues/244
 * @type {jQuery}
 */
var iCheck_cbs = $( ".some-form" ).find( "[class^='icheckbox_'] input[type=checkbox]" );
iCheck_cbs.on( 'ifChecked ifUnchecked', function ( event ) {
    $( event.target ).change();
});

Why this is not natively done by this plugin -- is beyond me, this is basic stuff.

drgullin commented 4 years ago

Thanks everyone, this issue will be fixed in 1.0.3.

drgullin commented 3 years ago

Thanks everyone! 👍

This is now supported by default, fixed with https://github.com/dargullin/icheck/commit/6f311edd715b1e8936419fccb2de17efa9948255.

dewelloper commented 3 years ago

Are you sure?