Search code examples
javascriptjquerycheckboxtwitter-bootstrap-3icheck

enable/disable input field depending on checkbox status


I have a problem disabling an input field when a checkbox is checked with a plugin called iCheck (http://fronteed.com/iCheck/).

Note: my code is working when the iCheck plugin is not used.

Working example without iCheck: http://jsbin.com/gusewu/1/

NOT working example when iCheck is included: http://jsbin.com/ludiqi/1/

Any help on debugging this would be appreciated. I've been on this for 2 days now. :-/


Solution

  • You should make use of ifChanged custom event:

    $('input').iCheck({
        checkboxClass: 'icheckbox_flat-blue',
        radioClass: 'iradio_flat'
    })
    .on('ifChanged', function() {
        $('#upload_image:input').prop('disabled', this.checked);
    })
    .trigger('ifChanged');
    

    Demo: http://jsbin.com/neheqocilu/2/edit