Comments (13)
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.
So any solutions?
from angular-bootstrap-switch.
Working on it.
from angular-bootstrap-switch.
+1
from angular-bootstrap-switch.
The problem appears to be about the execution order of the $watch
functions:
- the
radioOff
function should be executed before thengModel
check, but to do so thengModel
has to be delayed via a$timeout
call - the
switchActive
function should be executed after thengModel
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.
@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.
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 thedisabled
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.
@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.
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.
@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.
Fixed by 1829145
from angular-bootstrap-switch.
@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.
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)
- switch-change should only fire if the switch itself changed the value HOT 3
- switch-change should only fire if the switch itself changed the value HOT 5
- Can not set switch-on-text and switch-off-text to empty string HOT 5
- New release HOT 4
- triggering switchChange on model change breaks my app HOT 2
- Rendering issue with bootstrap-switch HOT 1
- can not pass event as parameter to switch-change event HOT 1
- Size does not work
- switch-change="onChange()" gets called immediately when loading HOT 7
- Support for angular 1.6 HOT 3
- confirmation for toggle switch HOT 2
- Does not initialize in Angular 1.5.11 project HOT 1
- Switch controlling / disabling another switch HOT 6
- Render bug HOT 1
- Switch in readonly does not change when i change model
- Delay to render the page HOT 1
- switch back to null?
- Switch not disabled on page load
- Click on inactive state should toggle switch
- null and undefined not supported in ngTrueValue/ngFalseValue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-bootstrap-switch.