vsn4ik / bootstrap-checkbox

A checkbox component based on Bootstrap framework.
https://vsn4ik.github.io/bootstrap-checkbox/
MIT License
213 stars 61 forks source link

Changing checked state via javascript doesn't update the label #35

Open bit5 opened 6 years ago

bit5 commented 6 years ago

When changing the state of the checkbox using jquery script, the checkbox doesn't switch visually.

Look at this code <input id="chk" type="checkbox") /> $('#chk').checkboxpicker(); $('#chk').prop('checked', false).trigger('change');

You will see the checkbox does not switch/toggle. Any idea how to fix it?

Cheers, Bit5

bit5 commented 6 years ago

This is similar with issue #34.

The problem is that I am using "trigger" to ensure the "change event" is raised. For quick workaround, I need to set the checked value to opposite value and then back to the actual value.

For example, the real value is FALSE, then do this: $('#chk').prop('checked', true); $('#chk').prop('checked', false);

As you can see, I've set the checked value to TRUE then set it back to FALSE.

I hope this help someone :)