[RECIPE]: bootstrapSwitch events firing
If you by any chance still have jQuery and use things like bootstrapSwitch, you can meet this situation:
When switch is setup like this
$('id').bootstrapSwitch('state', true)
you immediately can observe that switchChange
is fired. Which could be normal, not a big deal. But if you have system of several dependent toggles - it could lead to infinite loop or circular dependencies.
In my situation, I needed to differentiate between User Related event, when user clicks to the toggle in UI, and code event, when I set value in code. In the second case, I don't need to do additional actions (say, set object.changed = true).
It could be solved by using the third skip
parameter:
$('id').bootstrapSwitch('state', true, true)
Passing true
as third parameter notifies underlying code that you don't need to fire event right now.
p.s. this is one of such things, when you feel like there is simple solution, but spent about several hours to understand what is it.