bootstrap-switch icon indicating copy to clipboard operation
bootstrap-switch copied to clipboard

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

Open morrow95 opened this issue 5 years ago • 6 comments

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>

morrow95 avatar Jun 03 '19 19:06 morrow95

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

RouNNdeL avatar Jun 21 '19 20:06 RouNNdeL

It is still not working... Unfortunately!

poggialim avatar Jul 02 '19 09:07 poggialim

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

morrow95 avatar Jul 05 '19 18:07 morrow95

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

danielcsorba avatar Jul 18 '19 20:07 danielcsorba

Solved here with this:

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

souzaemarcal avatar Aug 27 '19 01:08 souzaemarcal

In the getClasses function, 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

jybleau avatar Oct 02 '19 19:10 jybleau