minhur / bootstrap-toggle

Bootstrap Toggle is a highly flexible Bootstrap plugin that converts checkboxes into toggles
http://www.bootstraptoggle.com
MIT License
1.48k stars 440 forks source link

Error, bootstrap-toggle can't render length when created in modal bootstrap #204

Open baotrv opened 5 years ago

baotrv commented 5 years ago

Hi, When i create one button toogle in boostrap , but it can't create length for the fit Please help me. untitled

artbrare commented 5 years ago

have the same problem :'(

malle-pietje commented 5 years ago

Struggling with the same issue. The quick and dirty fix is to make sure you initialize the toggle after the modal is shown, or if that's not possible, you can destroy/re-initialize the toggle after the modal was shown. You then need to also assign a width value.

Here's an example for a toggle inside an accordion element that is shown:

$('#collapse_id').on('shown.bs.collapse', function () {
    $('#input_with_toggle').bootstrapToggle('destroy').bootstrapToggle({
        size:     'small',
        onstyle:  'info',
        offstyle: 'default',
        width:    '52'
    });
});