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

Class definitions not created on outer div

Open dirkbez opened this issue 4 years ago • 4 comments

for version 3.3.5 The class assignments on the outer div do not work. The classes are "bootstrap-switch-undefined bootstrap-switch-undefined bootstrap-switch-undefined bootstrap-switch-undefined bootstrap-switch-undefined bootstrap-switch bootstrap-switch-wrapper bootstrap-switch-animate" It, therefore, does not honour the size assignment.

On inspection v.3.3.4 (as used by the Codepen) does seem to assign the classes correctly

dirkbez avatar Nov 24 '20 10:11 dirkbez

I have the same problem with incorrect classes for wrapper, Bootstrap Switch, version v3.3.4. Very strange, I don't understand what caused it...

it4joy avatar Jun 27 '22 11:06 it4joy

您好,您的来信已收到。 祝好 致礼!

ZHLHLTL avatar Jun 27 '22 11:06 ZHLHLTL

Same problem exists in v3.4.0.

It is caused by https://github.com/Bttstrp/bootstrap-switch/blob/2b316be8001254ef9f6e229144b625c4674560cb/src/js/bootstrap-switch.js#L15

The filter is wrong. I believe it should be

return [
    state ? 'on' : 'off',
    size,
    disabled ? 'disabled' : undefined,
    readonly ? 'readonly' : undefined,
    indeterminate ? 'indeterminate' : undefined,
    inverse ? 'inverse' : undefined,
    id ? `id-${id}` : undefined,
  ].filter(v => v != null);

or, to be more coherent with the values in the array:

return [
    state ? 'on' : 'off',
    size,
    disabled ? 'disabled' : undefined,
    readonly ? 'readonly' : undefined,
    indeterminate ? 'indeterminate' : undefined,
    inverse ? 'inverse' : undefined,
    id ? `id-${id}` : undefined,
  ].filter(v => v != undefined);

But you certainly don't want to apply a filter to keep undefined values.

fmarchalemisys avatar Dec 08 '22 16:12 fmarchalemisys

您好,您的来信已收到。 祝好 致礼!

ZHLHLTL avatar Dec 08 '22 16:12 ZHLHLTL