bantikyan / icheck-material

Pure css material checkboxes and radio buttons.
https://bantikyan.github.io/icheck-material/
MIT License
35 stars 11 forks source link

How to make icheck-material work with table rows? #2

Closed carlo-fontanos closed 5 years ago

carlo-fontanos commented 5 years ago

Hi,

I am trying to make a table row click to check the box. Bellow is what I have tried so far:

$('table').on('click', tr', function(e){
    if(e.target.type !== 'checkbox'){
        $(':checkbox', this).trigger('click');
    }
});

Above works, but when I click the checkbox it triggers twice. Any idea how to fix this?

bantikyan commented 5 years ago

Hi @carlo-fontanos . The problem you describe is not related with icheck-material, you will get same issue when dealing with regular checkboxes.

But maybe one solution will be if you change your code this way:

$('table').on('click', 'tr', function(e) {
    if (e.target.parentElement.className.startsWith('icheck-material')) {
        e.stopPropagation();
    }
    else {
        $(':checkbox', this).trigger('click');
    }
});