Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switchState doesn't trigger when indeterminate is set #426

Open
cristalembalagens opened this issue Feb 2, 2015 · 5 comments
Open

switchState doesn't trigger when indeterminate is set #426

cristalembalagens opened this issue Feb 2, 2015 · 5 comments
Assignees

Comments

@cristalembalagens
Copy link

If the initial state is not checked and data-indeterminate is true, when the button is hit on the off side it becomes on and triggers the switchState event, but if you hit on the on side, it becomes off and doesn't trigger the switchState event because it was already off but, it was set to be in indeterminate state so the event must consider that the state is not checked or unchecked.

Here's a fiddle to explain this case http:https://jsfiddle.net/2m4b4bb2/

@rfox90
Copy link

rfox90 commented Feb 8, 2015

+1, exact same problem found and came here to report it. Thanks for the fiddle. Might see if I can fix it and pull request.

@rfox90
Copy link

rfox90 commented Feb 9, 2015

@cristalembalagens Set the state option to null when using indeterminate.

Then the event will trigger.

For more info see here: https://github.com/nostalgiaz/bootstrap-switch/blob/master/dist/js/bootstrap-switch.js#L499

The plugin catches the event and only retriggers it if it has changed.

Updated fiddle: http:https://jsfiddle.net/2m4b4bb2/3/

@cristalembalagens
Copy link
Author

@rfox90 great solution. The only different thing I had to do is to initiate those checkboxes without indeterminate with the normal initiation and those with indeterminate with {state:null}. Using data-state=null didn't work.

There's still a problem, once you set a value, if you need to turn it to indeterminate again, you can't set state to null again.

@CatarinaPBressan
Copy link

👍

@rfox90's solution worked for now.

@shimikano
Copy link

I ran into this as well.

@cristalembalagens: You can set the state after the initialization -- in particular, whenever you set the switch to indeterminate -- using something along the following lines:

element.data('bootstrap-switch').options.state = null; // or anything else other than true and false

As another side note, the line that is responsible for this bug should be linked more permanently like this: https://github.com/nostalgiaz/bootstrap-switch/blob/a39a1e/dist/js/bootstrap-switch.js#L530

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants