abpetkov / switchery

iOS 7 style switches for your checkboxes
http://abpetkov.github.io/switchery/
2.06k stars 477 forks source link

Programmatically trigger the switch. #94

Closed ecarter202 closed 8 years ago

ecarter202 commented 8 years ago

It would be nice to be able to say, if not switched on, switch on.

gregorythrush commented 8 years ago

I have the same request. I'm using a javascript function to select or un-select a group of checkboxes.

<input type="checkbox" name="participant" class="js-switch case" value="45464" id="45464">

$("#selectall").click(function () {
      $('.case').attr('checked', this.checked);
});

The Switchery class 'js-switch' appears to intercept / interfere with the code above. Any advice is appreciated.

JayAdra commented 8 years ago

Try using prop instead of attr: http://api.jquery.com/prop/

Eabittan commented 8 years ago

Check the answer from @svetlinyotov here: https://github.com/abpetkov/switchery/issues/92 it worked for me

CaptainHypertext commented 8 years ago

This plugin is all but useless without this functionality.

abpetkov commented 8 years ago

Somewhere towards the end of https://github.com/abpetkov/switchery/issues/27 you'll find a working demo of how to handle checked state dynamically. In short - you check the native input and fire a change event.

Closing this issue, since it's a duplicate.