Code Monkey home page Code Monkey logo

Comments (13)

aarro avatar aarro commented on May 29, 2024

I'm experiencing this same issue, although removing the timeout as mentioned above doesn't do anything for me.

If you start with isActive = false in the above example, notice that when you enable the switch the wrong value is showing.

from angular-bootstrap-switch.

yantakus avatar yantakus commented on May 29, 2024

So any solutions?

from angular-bootstrap-switch.

frapontillo avatar frapontillo commented on May 29, 2024

Working on it.

from angular-bootstrap-switch.

peruzzo avatar peruzzo commented on May 29, 2024

+1

from angular-bootstrap-switch.

frapontillo avatar frapontillo commented on May 29, 2024

The problem appears to be about the execution order of the $watch functions:

  • the radioOff function should be executed before the ngModel check, but to do so the ngModel has to be delayed via a $timeout call
  • the switchActive function should be executed after the ngModel check, but the previous $timeout call messes things up

I don't see a feasible solution but the one of asking @nostalgiaz to allow the toggling even if the switch is disabled.

from angular-bootstrap-switch.

LostCrew avatar LostCrew commented on May 29, 2024

@frapontillo i talk mostly principle-driven. if instead of the switch we consider a normal checkbox, it would be impossible to toggle it in disable state. period.
i haven't looked closely at the issue in question and i am not dogmatically against allowing an optional force flag to be passed to the state toggle method. however, i believe that its existence must be justified by a very strong reason.
i would rather spend more time trying to fix the issue the hard way, for now. and i can obviously help with that.

from angular-bootstrap-switch.

frapontillo avatar frapontillo commented on May 29, 2024

The issue is due to how angular digest cycles work:

  • you ask in a controller to - first - set the switch to "on"
  • then you ask the controller to disable the switch
  • what happens is that both codes are executed in a single $digest cycle, and the disabled part somehow gets triggered before the model
  • when the model is handled the switch is already disabled, so the value is updated but the state isn't toggled on the switch

I am now trying to handle everything in a cleaner way, but this will probably require some time.
Of course, PRs are very welcome, be sure to test them against all use cases though.

from angular-bootstrap-switch.

LostCrew avatar LostCrew commented on May 29, 2024

@frapontillo again, i haven't taken look at the code and am relatively new to angular. did you perhaps try to:

  • wrap the two calls in $timeout?
  • wrap the two calls in $evalAsync?
  • a combination of the ones above: wrap the first call in $timeout and the second in $evalAsync?

from angular-bootstrap-switch.

frapontillo avatar frapontillo commented on May 29, 2024

I am trying to remove every asynchronous call from the directive, it was a terrible hack I don't like anymore ✂️

from angular-bootstrap-switch.

frapontillo avatar frapontillo commented on May 29, 2024

@LostCrew I am about to fix this issue and some more; the way I solved it was by wrapping the deactivation call in a $timeout in order to force the state to be applied before the disabled.

I still feel like this is an awful hack, it'd be great if you could implement (no rush at all) a force parameter to the setState method. This would also solve the following workflow that should be supported:

  • a user loads a page with the switch being disabled because of some permission issues
  • the page automatically refreshes its values every 10 minutes
  • the boolean value bound to the switch changes
  • the new boolean value should be reflected in the switch state, which as of now does not because of this limitation

from angular-bootstrap-switch.

frapontillo avatar frapontillo commented on May 29, 2024

Fixed by 1829145

from angular-bootstrap-switch.

frapontillo avatar frapontillo commented on May 29, 2024

@blindworld @aarro @web2style @peruzzo can you confirm that the latest commits in the develop branch solve this issue? #39 is waiting for your confirmation.

Thanks.

from angular-bootstrap-switch.

blindworld avatar blindworld commented on May 29, 2024

Sorry for the lack of update, I actually have moved from the project that was using this directive to a different project. I alerted my previous team that your update is available for them to test, but I'm not sure if any of them actually have a github account.

from angular-bootstrap-switch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.