0

I am using Bootstrap Switch in my project to show a warning flag. Each time I try to set value of switch from false to true dynamically it is not going in .bootstrapSwitch().on method. It is working fine on changing switch state from false to true dynamically. Fiddle below-

http://jsfiddle.net/aanurn0j/

nickalchemist
  • 2,211
  • 6
  • 31
  • 58

1 Answers1

3

Set third parameter to false and it works.

$('#toggleSwitchOn').click(function () {
    $('#bootstrapswitch').bootstrapSwitch('state', true, false);
});

jsFiddle

ankur140290
  • 640
  • 9
  • 25
  • I didn't understand logic behind this – nickalchemist Aug 12 '15 at 11:03
  • The method state can receive an optional third parameter skip. if true, switchChange event is not executed. The default is false. – ankur140290 Aug 12 '15 at 11:09
  • I need something else, $(this).bootstrapSwitch({ onSwitchChange: function(e, state) { if(state == false){ //do something }else{ //do something } } }); Also, I need to make the switch to be ON! – Raru Feb 28 '20 at 10:44