gitbrent / bootstrap4-toggle

Bootstrap 4 Switch Button / Toggle
https://gitbrent.github.io/bootstrap4-toggle/
MIT License
213 stars 67 forks source link

OnClick event never fires ! #37

Open Mina-R-Meshriky opened 4 years ago

Mina-R-Meshriky commented 4 years ago

Only the Change event is firing correctly, but the on click event never fires.

 <input title="Activation status" type="checkbox" class="de-activate" checked
                               data-toggle="toggle" data-size="small" data-onstyle="success"
                               data-on="Activated" data-off="Deactivated">
 $('.de-activate').click( (e)=>{
            let el = $(e.target);
            console.log(el);
        });

I need the click event, since I want to show a warning before changing the state of the toggle

jonmnoj commented 4 years ago

I've just run into this problem, managed to work around it by enclosing the input in a div and then using a delegated click event on .toggle for that div, this picks it so I can do a check first.

<div class="toggle-div"><input class="toggle-option" type="checkbox" data-toggle="toggle"></div>

$('.toggle-div').on('click', '.toggle', function(e) { e.preventDefault(); e.stopPropagation(); console.log('clicked')});