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

Indeterminate state not triggered

Open kubijo opened this issue 9 years ago • 19 comments

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

kubijo avatar May 04 '15 16:05 kubijo

Acknowledged, thanks for reporting this!

frapontillo avatar May 04 '15 16:05 frapontillo

Hi. Do you have some estimation for the fix?

kubijo avatar May 15 '15 07:05 kubijo

Sorry @kubijo, I have no idea when I'll be able to work on this. :(

frapontillo avatar May 15 '15 08:05 frapontillo

I see. Well lets hope you'll get some time soonish. Thanks for reply.

kubijo avatar May 15 '15 08:05 kubijo

We are having the same issue, hope you can fix this soon.

vanderlindenjc avatar Jun 12 '15 08:06 vanderlindenjc

Sorry for keeping you guys wait, the change is now available in the develop branch (also with angular-1.4.0 support).

frapontillo avatar Jun 13 '15 09:06 frapontillo

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 avatar Aug 21 '15 12:08 mirow

@mirow you're right, I am going to reopen this.

frapontillo avatar Aug 21 '15 12:08 frapontillo

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.)

mirow avatar Aug 26 '15 11:08 mirow

Can you try it with 0.5.0?

frapontillo avatar Mar 10 '16 12:03 frapontillo

In version 0.5.0 the switch is always in the state indeterminate - regardless of the model value!

adestis-ds avatar Mar 16 '16 18:03 adestis-ds

@adestis-ds that's impossible, all tests pass and you can see that the behavior is correct at the demo in the first post.

frapontillo avatar Mar 16 '16 20:03 frapontillo

Closing due to inactivity.

frapontillo avatar Mar 29 '16 10:03 frapontillo

Still buggy. When state is ON, then set model to NULL, then click the swiotch, the model is empty but visual state display OFF.

skapin avatar Apr 25 '16 08:04 skapin

It's clearly not working. Lol... why was the issue closed.

jnicolau avatar Jul 31 '16 20:07 jnicolau

@jnicolau then feel free to post a breaking sample.

frapontillo avatar Aug 01 '16 06:08 frapontillo

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.

mirow avatar Aug 01 '16 06:08 mirow

So it is an issue related to switching from false to undefined.

frapontillo avatar Aug 01 '16 06:08 frapontillo

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.

westerncj avatar Aug 24 '16 14:08 westerncj