vsn4ik / bootstrap-checkbox

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

Checked and Unchecked is wrong... #34

Open bit5 opened 6 years ago

bit5 commented 6 years ago

When using this checkbox, the checked and unchecked is reversed.

Look at this code <input id="chk" type="checkbox" checked) />

You will see that the "NO" has been selected. And when you use in the js it is totally wrong! The No will be "TRUE" and Yes will become "FALSE". $('#chk').checkboxpicker(); $('#chk').change(function () { alert ($(this).is(":checked")); }); $('#chk').prop('checked', false).trigger('change');

Any idea how to fix it?

Cheers

bit5 commented 6 years ago

I found the problem. 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 :)

joweste commented 5 years ago

It doesn´t work to me