gitbrent / bootstrap4-toggle

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

Change event firing multiple times (3 times) per toggle #57

Closed joshbrekke closed 3 years ago

joshbrekke commented 3 years ago

The toggle control appears to fire 3 times per toggle. Here's a example to replicate the issue...

Markup:

<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/css/bootstrap4-toggle.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/js/bootstrap4-toggle.min.js"></script>

<input id="toggle" type="checkbox" data-toggle="toggle" data-on="Active" data-off="In-Active" data-onstyle="success" data-offstyle="danger" data-size="sm">

JavaScript:

<script>
$(document).ready(function () {
  $('#toggle').change(function () {
      console.log($(this).prop("checked"));
  });
}
</script>

Console Output:

false
true
false

Has anyone else experienced this issue before?

Thanks,

Josh

joshbrekke commented 3 years ago

Still testing.