Bttstrp / bootstrap-switch

Turn checkboxes and radio buttons in toggle switches.
MIT License
5.08k stars 1.44k forks source link

3.4 doesn't respect checked/unchecked in html any more #707

Open morrow95 opened 5 years ago

morrow95 commented 5 years ago

checked / unchecked specified in the html of the input is no longer respected with version 3.4. They will always show in an 'off' state regardless of the true state of the input when loaded.

An example is shown below. This worked perfectly fine with version 3.3.4, yet in 3.4 this will show the switch in an off state when it clearly has 'checked' in the html.

<input type="checkbox" class="make-switch" data-size="small" data-label-width="15" data-on-color="success" data-off-color="danger" data-on-text="Yes" data-off-text="No" name="name" value="1" checked>

RouNNdeL commented 5 years ago

Has anyone managed to fix it, other then using an older version?

poggialim commented 5 years ago

It is still not working... Unfortunately!

morrow95 commented 5 years ago

I didn't bother comparing the js from the old/new, but something definitely changed within it to cause this issue.

danielcsorba commented 5 years ago

In the getClassesfunction, the filter's return should be return v !== null; instead of ==.

souzaemarcal commented 5 years ago

Solved here with this:

$(function() {
    $('[data-switch="true"]').each(function () {
        $(this).bootstrapSwitch({ state: $(this).is(':checked') }).trigger('change');
    });
});
jybleau commented 5 years ago

In the getClassesfunction, the filter's return should be return v !== null; instead of ==.

Shouldn't it be return v != null; to also include undefined value ? Because v seems to be undefined instead of null...

The strict operator still leads to classes like this: bootstrap-switch-undefined