0

So I'm working on my usergroups page on my cms, and I added a switch to determine if the group has access to the admin section or not. If so (and the user checks the switch), a div of permissions will be displayed. For this, I used Bootstrap's plugin Bootstrap Switch.

Here is the code:

$(document).ready(function() {
            $('input#isAdmin').bootstrapSwitch();
            $('#permissions_multi_select').multiSelect();
            $('#permissions_div').hide();

            $('input#isAdmin').on('switchChange.bootstrapSwitch', function() {
                if ($('input#isAdmin').state)
                    $('#permissions_div').show();
                else
                    $('#permissions_div').hide();
            });
        });

If I change the show() or hide() methods with an alert of $('input#isAdmin').state, or .attr('checked') or .checked, I get 'undefined'.

Any ideas?

Naxon
  • 1,354
  • 4
  • 20
  • 40

1 Answers1

2

Replace $('input#isAdmin').state with $('input#isAdmin').bootstrapSwitch('state') in the condition

$('input#isAdmin').bootstrapSwitch();
$('#permissions_multi_select').multiSelect();
$('#permissions_div').hide();

$('input#isAdmin').on('switchChange.bootstrapSwitch', function() {
    if ($('input#isAdmin').bootstrapSwitch('state'))
        $('#permissions_div').show();
    else
        $('#permissions_div').hide();
});

Working fiddle: http://jsfiddle.net/o2y5mhpr/1/

j3ff
  • 5,719
  • 8
  • 38
  • 51