angular-bootstrap-switch
angular-bootstrap-switch copied to clipboard
Indeterminate state not triggered
When the ng-model
bound variable is undefined, it is said that the switch should be in indeterminate state - that however does not work. Below is link to plunker.
http://plnkr.co/edit/1SaSvTIzOeyjqWCl4GLH?p=preview
Acknowledged, thanks for reporting this!
Hi. Do you have some estimation for the fix?
Sorry @kubijo, I have no idea when I'll be able to work on this. :(
I see. Well lets hope you'll get some time soonish. Thanks for reply.
We are having the same issue, hope you can fix this soon.
Sorry for keeping you guys wait, the change is now available in the develop
branch (also with angular-1.4.0 support).
There is still the problem that the switch does not always come out of the indeterminate state when you click on it. You can see this in the same plunker: http://plnkr.co/edit/1SaSvTIzOeyjqWCl4GLH?p=preview To reproduce: set switch to 'ON', then click on "Toggle undefined", then click on the switch. The switch is now in the 'OFF' state, but the model value wasn't updated, it's still undefined.
@mirow you're right, I am going to reopen this.
I think you need to set the state to null when the state is indeterminate (as explained here: https://github.com/nostalgiaz/bootstrap-switch/issues/426 )
Maybe you could always set the state to null in the bootstrapSwitch constructor, and update the state in scope.$watch?
Also, currently you only check if the model value matches the true value, you don't check whether it matches the false value. Instead you should do something like this:
if (newValue === getTrueValue()) {
element.bootstrapSwitch('state', true, false);
element.bootstrapSwitch('toggleIndeterminate', false, true);
} else if (newValue === getFalseValue()) {
element.bootstrapSwitch('state', false, false);
element.bootstrapSwitch('toggleIndeterminate', false, true);
} else {
element.bootstrapSwitch('state', null, false);
element.bootstrapSwitch('toggleIndeterminate', true, true);
}
(This is actually to fix a slightly different bug: if the model value is undefined, then the switch is set to indeterminate state correctly. But if the model value is null, then the switch is set to 'false' state, no matter what the ng-false-value is.)
Can you try it with 0.5.0?
In version 0.5.0 the switch is always in the state indeterminate - regardless of the model value!
@adestis-ds that's impossible, all tests pass and you can see that the behavior is correct at the demo in the first post.
Closing due to inactivity.
Still buggy. When state is ON, then set model to NULL, then click the swiotch, the model is empty but visual state display OFF.
It's clearly not working. Lol... why was the issue closed.
@jnicolau then feel free to post a breaking sample.
There's a new, slightly different, bug: http://plnkr.co/edit/1SaSvTIzOeyjqWCl4GLH?p=preview Set value to false, then click on "Toggle undefined". The visual state should become indeterminate, but it remains OFF.
So it is an issue related to switching from false to undefined
.
Are there any updates to this bug? When ng-model
is set to undefined
from a true state, it toggles to indeterminate. When it's set to undefined
from a false state, indeterminate is not toggled.