Code Monkey home page Code Monkey logo

angular-bootstrap-switch's People

Contributors

alexbeletsky avatar aprilssmile avatar bardusco avatar bryant1410 avatar fiznool avatar frapontillo avatar icholy avatar psyho avatar romanblanco avatar s10z avatar sparkyfen avatar tucq88 avatar vincent-leonardo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-bootstrap-switch's Issues

Boolean value error

If you define ng-true-value="1" ng-false-value="0" (note there is only 0 not '0') than You have to click twice for false value.

Trigger digest cycle in bootstrap-switch event handler

Hi,

The event handler which updates the the ng-model does not trigger the angular digest cycle, which causes the model to not be updated immediately. The code in question is src/directives/bsSwitch.js#L199.

You should add the following to make the changes immediate:

scope.$apply();

Here are some links about $apply:

http://jimhoskins.com/2012/12/17/angularjs-and-apply.html
https://docs.angularjs.org/api/ng/type/$rootScope.Scope

Sorry about no giving you a pull request, did not have any time to fork your project on GitHub.

Anyways thanks for the great angular extension for bootstrap-switch.

Binding issues

Hi,

I've found that if I bind switch-active to a model and the model value is false then changing the model in the controller doesn't update the switch UI - its as if it stays in a disabled state even as far as to prevent binding from working and updating the switch state.

Because of this issue I tried binding to switch-readonly and have found that I cannot get it to bind to the same model value at all.

Even switch-readonly="true" and switch-readonly="{{true}}" don't work...? Is this a bug?

element.bootstrapSwitch undefined

when i wire up and run with the angular version i get an error stating that the bootstrapSwitch is undefined.

i was trying to test to see if ng-true-value="0" and ng-false-value="1" work with this control. Seems to work with the jquery version but of course then i would need a directive to talk with the model. Prefer to go this route.

aaron

Prevent swith to post

Hi,

I try to use this module but on each switch I make, it works as expected but it also makes a POST request on my current page. How can I prevent that? Is it related to the switch button or I made something wrong elsewhere?

Also, I have another page where I need to actually switch twice my button before it actually does something. (The modelValue or viewValue is not initialize correctly). Do you have ever seen something like that? For sure, I made a mistake but can't find the cause.

Cheers!

use IIFE to wrap 'use strict'

putting 'use strict' globally forces the strict mode on entire application.

It's better to wrap in IIFE, adding 'use strict' in inner scope.

Working with 1 and 0

Now Yor script work with true/false - can You make it to work with 1/0 as well?? I mean init state - if value=1 then value=true - now if value=1 it's off

On browser refresh directive is broken and not functional

If a press F5 or something similar the directive simply doesn't work.

<slide-toggle on-label="Published" off-label="Unpublished" ng-model="form.settings.published" class="pull-right "></slide-toggle>

That's the my simple code, but this is hapening also in the example.
I have try it with almost every browser.

Push it to npm

For browserified based projects is really important to have components in npm. It would be great if you push this to npm as well. :)

Switch not displaying properly if parent initially hidden

If the parent is hidden initially, control does not display properly as the dimensions cannot be calculated. Is there something that can be done to trigger a "recalc"?

From the bootstrap-switch issues: Bttstrp/bootstrap-switch#376

The solution here was to call $('.my-bs-switch-input').bootstrapSwitch('_width'); when visible. Needs support for ng-show/hide perhaps.

Some attributes does not working

I'm trying to use your directive as part of a template within an another directive. Some of attributes gets ignored: switch-readonly, switch-label-width, switch-handle-width. Also the value of ng-true-value and ng-false-value are not working correctly. I added a watch for the ng-model value, but the replied value after toggle is always '' (empty string)

"angular": "~1.2.26",
"jquery": "~2.1.0",
"bootstrap": "~3.2.0",
"bootstrap-switch":"3.0.2",
"angular-bootstrap-switch": "~0.3.0"

Does not respect ngTrueValue/ngFalseValue

I have the following checkbox, that works correctly when I dump the object out into the view with {{ component | json }}:

<input type="checkbox" 
    data-ng-model="component.contains" 
    ng-true-value="1" ng-false-value="0"/>

However, adding the bs-switch directive causes the model to get 'stuck' in the on position:

<input type="checkbox" 
    bs-switch
    data-ng-model="component.contains" 
    ng-true-value="1" ng-false-value="0"/>

The switch moves back and forth, but the underlying model is not updated, rather it stays at "1"

Is there a workaround where you can use 1/0 instead of true/false?

Existing ngModel inject to the directive

Hi,

I'm not sure is it intended to work like this?

capture

In the example application there are 3 scopes, and each has it's own $scope.isSelected model. And these are working separately.

What i need is to bind the model to an exsiting value, to do it i modifed the directive and it's usage, i have added :

  template: '<input ng-model="myDirectiveVar">',
  scope: {
    myDirectiveVar: '=', 

...

And the usage is :
bs-switch my-directive-var="isSelected"

capture2

Is this the only way to pass existing model variable to this directive?

Error message when adding module

Here how I am adding the module to my app:

var theApp = angular.module("theApp", ["sizeFilter", "frameRateFilter", "bitRateFilter", "angularBootstrapNavTree", "ngAnimate", "nvd3", "mgcrea.ngStrap.select", "frapontillo.bootstrap-switch"
]);

When I add this module to my app, I immediately get the following error in my console. I'm assuming there is a possible incompatibility between angular-bootstrap-switch and one of the other modules or libs that I have installed.

http://localhost:9000/admin/webjars/jquery/2.1.1/jquery.min.js is being assigned a //# sourceMappingURL, but already has one
http://localhost:9000/admin/webjars/angularjs/1.3.6/angular.min.js is being assigned a //# sourceMappingURL, but already has one
http://localhost:9000/admin/webjars/angularjs/1.3.6/angular-animate.min.js is being assigned a //# sourceMappingURL, but already has one
http://localhost:9000/admin/webjars/angular-strap/2.1.4/angular-strap.min.js is being assigned a //# sourceMappingURL, but already has one
mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create d3.js:486
Error: [$injector:modulerr] http://errors.angularjs.org/1.3.6/$injector/modulerr?p0=theApp&p1=%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.3.6%2F%24injector%2Fmodulerr%3Fp0%3Dfrapontillo.bootstrap-switch%26p1%3D%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.3.6%252F%2524injector%252Fnomod%253Fp0%253Dfrapontillo.bootstrap-switch%250AA%252F%253C%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A6%253A409%250AMd%252F%253C%252F%253C%252F%253C%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A21%253A328%250Aa%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A20%253A464%250AMd%252F%253C%252F%253C%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A21%253A211%250Ag%252F%253C%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A35%253A273%250Ar%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A7%253A288%250Ag%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A35%253A123%250Ag%252F%253C%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A35%253A281%250Ar%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A7%253A288%250Ag%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A35%253A123%250AOb%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A38%253A358%250Asc%252Fd%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A17%253A348%250Asc%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A18%253A146%250AHd%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A16%253A490%250A%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fangularjs%252F1.3.6%252Fangular.min.js%253A249%253A238%250An.Callbacks%252Fj%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fjquery%252F2.1.1%252Fjquery.min.js%253A2%253A26852%250An.Callbacks%252Fk.fireWith%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fjquery%252F2.1.1%252Fjquery.min.js%253A2%253A27661%250A.ready%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fjquery%252F2.1.1%252Fjquery.min.js%253A2%253A29482%250AI%2540http%253A%252F%252Flocalhost%253A9000%252Fadmin%252Fwebjars%252Fjquery%252F2.1.1%252Fjquery.min.js%253A2%253A29656%250A%0AA%2F%3C%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fangularjs%2F1.3.6%2Fangular.min.js%3A6%3A409%0Ag%2F%3C%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fangularjs%2F1.3.6%2Fangular.min.js%3A36%3A28%0Ar%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fangularjs%2F1.3.6%2Fangular.min.js%3A7%3A288%0Ag%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fangularjs%2F1.3.6%2Fangular.min.js%3A35%3A123%0Ag%2F%3C%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fangularjs%2F1.3.6%2Fangular.min.js%3A35%3A281%0Ar%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fangularjs%2F1.3.6%2Fangular.min.js%3A7%3A288%0Ag%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fangularjs%2F1.3.6%2Fangular.min.js%3A35%3A123%0AOb%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fangularjs%2F1.3.6%2Fangular.min.js%3A38%3A358%0Asc%2Fd%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fangularjs%2F1.3.6%2Fangular.min.js%3A17%3A348%0Asc%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fangularjs%2F1.3.6%2Fangular.min.js%3A18%3A146%0AHd%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fangularjs%2F1.3.6%2Fangular.min.js%3A16%3A490%0A%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fangularjs%2F1.3.6%2Fangular.min.js%3A249%3A238%0An.Callbacks%2Fj%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fjquery%2F2.1.1%2Fjquery.min.js%3A2%3A26852%0An.Callbacks%2Fk.fireWith%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fjquery%2F2.1.1%2Fjquery.min.js%3A2%3A27661%0A.ready%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fjquery%2F2.1.1%2Fjquery.min.js%3A2%3A29482%0AI%40http%3A%2F%2Flocalhost%3A9000%2Fadmin%2Fwebjars%2Fjquery%2F2.1.1%2Fjquery.min.js%3A2%3A29656%0A angular.min.js:6

Got error on height after build

use follow code:

<input bs-switch
ng-model="advancedSwitch.value"
type="{{advancedSwitch.type}}"
switch-size="{{advancedSwitch.switchSize}}"
switch-label="{{advancedSwitch.switchLabel}}"/>

got follow result after run grunt build:
2014-11-11 18 18 13
totally confused.
(P.S. everything is OK under grunt serve)

Missing bootstrap-switch options

Could you add the remaining options from the jQuery plugin (inverse, readonly, disabled, events...)? Or, maybe also/instead allow you to pass a json string into the input attribute and eval that and pass it into the jquery instantiation of bootstrapSwitch? Could make things simpler on your end anyway.

<input bs-switch="{size: 'mini', 'switch-on-color':'primary' }"/>

and then in link:

angular.element(element).bootstrapSwitch(scope.$eval(attrs.bsSwitch));

Open to anything - and at your leisure of course! ๐Ÿ˜ƒ

$destroy handling make angular crash when changing view in angular 1.2.0-rc2

Hello,

The call to

scope.$on('$destroy', function() {
        element.bootstrapSwitch('destroy');
});

Seems to make angular crash during scope cleanup ( when changing/togling view, either with ng-view, ng-if or any other view based directive )

Commenting these lines fixes the issue ( not even sure if there are sides effects because all bootstrapSwitch data are bound to the element, so 'naturally' cleaned up during element removal )

This seems to be caused because the call to bootstrapSwitch's destroy method remove the element from the DOM, messing up with angular scopes cleaning.

Stack :

TypeError: Cannot read property '$$nextSibling' of null
at Scope.$broadcast (http://localhost:9000/libs.js?v=1.0.0:51078:57)
at Scope.$destroy (http://localhost:9000/libs.js?v=1.0.0:50759:14)
at Scope.$delegate.proto.$destroy (:812:29)
at cleanupLastView (http://localhost:9000/libs.js?v=1.0.0:61044:26)
at http://localhost:9000/libs.js?v=1.0.0:61060:15
at publicLinkFn (http://localhost:9000/libs.js?v=1.0.0:45315:29)
at update (http://localhost:9000/libs.js?v=1.0.0:61059:13)
at Scope.$broadcast (http://localhost:9000/libs.js?v=1.0.0:51068:28)
at http://localhost:9000/libs.js?v=1.0.0:60765:26
at wrappedCallback (http://localhost:9000/libs.js?v=1.0.0:49873:81)

bs-select won't read ng-model

I assume I'm doing something wrong, but I cannot get the bs-select element to actually sync with the ng-model. I did get past the previous issue, which was that I didn't have the correct .js files included. I have "frapontillo.bootstrap-switch" in my app module list. I have the following css and js files included in my HTML:

bootstrap-switch.min.css
bootstrap-switch.min.js
angular-bootstrap-switch.min.js

Here is the code I am using:

The value is Off when I visit the page. When I click it to turn it on, and then leave and return to the page, it is back Off. I added {{ service.output.rtmp.enabled }} next to it to confirm that the switch is indeed not changing the value of the model.

What else am I possibly missing? I am temporarily using a similar plugin called angular-toggle-switch that I am able to get working, but I would prefer to use your plugin, as it has a richer set of features. I tried to look at the example on this site for guidance, but it's hard to compare to that one, as it uses a different set of file names in the required libraries.

A switch that is not visible on page load will not be properly initialized

Using:
bootstrap-switch: v3.0.2
angular-bootstrap-switch: v0.4.0-alpha.1 - 2014-11-21
angularjs: 1.3.6

If the switch is within a tab that isn't initially visible, then it will not be initialized properly with the value of its ng-model. This is also true with other components that contain/hide the switch like angular-wizard, angular-material tabs (md-tab), etc.

The scope.$watch(attrs.ngModel, function (newValue) { is called properly and sets the state on the element. Later when the element becomes visible, the value is correct but the display state is not.

We're currently working around the issue by setting up an interval which polls to see when the element becomes visible and then makes the call to:

element.bootstrapSwitch('state', newValue === getTrueValue(), true);

This seems to set both the value and display state properly so that they stay in sync, There is likely a better solution.

This does not appear to be covered by an existing test since I was able to clone the project and run the Karma tests with AngularJS 1.3.6. They all passed.

Event Handling

$scope.$watch('isSelected', function() {
$log.info('Selection changed.');
console.log("IS selected")
});

                        $scope.toggleActivation = function() {
                            $log.info('toggle Activation');
                            console.log("toggle selected")
                          $scope.isActive = !$scope.isActive;
                        }

keeping above in controller, none of them fired when checkbox is changed. However when checkbox switch created above 2 function fired but not after that. Any ideas?

model binding disabled when switch not active

Hey there!

Firstly, thanks for the sweet little directive you made! I'm really enjoying it.
I'm not sure if this is desired behaviour, but when I de-activate a switch I can no longer change the switch state via my model data.

I am using switch-active to disable the switch to dis allow user interaction, but I still need to be able to change the model value it is bound to for returning http response data.

Any help or suggestions will be much appreciated =)

Disabled but showing value

Is it possible to disable the switch and yet reflect the value of the model?

I have tried setting switch-active to false but it makes the switch turn of even though the underlying boolean reads true.

Furthermore I have been trying to set ng-readonly and ng-disabled with no luck.

First toggle do not change ngModel value

Hey,

Greate direcitve:) I have a small issue, the first toggle do not change the value of ngModel, if I call

controller.$setViewValue(controller.$modelValue); 

just after

element.bootstrapSwitch('state', controller.$modelValue || false, true); (line 121)

it works, do that make sense?

-KFIIL

dont work in angular 1.2.6

in the angular-bootstrap-switch.js file.

i add a row in the link function first.
element = $(element);

its work

Radio button sample

Could you provide any sample code for radio button implementation (plunkr or something)? I am having a hard time to make this work with radio buttons and could not find a sample code anywhere.

ngModel updates after 3 switches

when the ngModel is initially true and the checkbox is "on", the first time i uncheck it the ngModel does not update but stays true. I have to recheck it and then re-uncheck it to update the ngModel.

Switch animates when first rendered if ngModel attr is true

When the switch is first rendered, if the ngModel attribute resolves to true, the switch animates from the off to on state, since the data binding has moved from false -> true.

Is there any way to stop this happening without disabling animations completely?

mini switch should be narrower

I am trying to use a mini switch, and I think with min-width in the CSS of 100 px is too wide. See attached image:
screen shot 2014-04-11 at 3 46 47 pm
I would like this mini switch to be half as wide (horizontally) than it is. It looks more balance and less "skinny".

However, setting the CSS seems to mess up the clickable area of the switch. Can you either update or explain how to make the mini switch 50px min-width instead of 100?

Is it possible to add an ng-click event to the switch?

depending on the id the switch gives to a function I will change something. So I have to watch multiple switches and react on there ids? Is it possible to add a ng-click="doSomething(id1)"? Or is there a better way doing this? Thank you!

Jquery problem

I think the whole idea of making angular directive is to avoid jquery usage...

Help getting a Plunk working?

Hi, @frapontillo ! Thanks for the cool directive!

I'm trying to add it to my project, and I'm running into one weird issue. I'm trying to construct a Plunk to demonstrate the problem so I can create an actual issue for it, but I can't quite get the Plunk working. I'm hoping someone can help me fix it so we can have a good starting place for testing issues, etc.

http://plnkr.co/edit/Stx9nVyyR3AdMgD7tHji?p=preview

If you have your console open, you'll see that the bootstrapSwitch() function is undefined.

Thanks in advance for your help!

Cannot disable and toggle value at the same time.

Changing the value of the switch & setting isActive to false at the same time results in only the model value changing with the switch's position being opposite.

assuming the value is false, calling:

$scope.switchValue = true;
$scope.switchActive = false;

will result in the switch being disabled in the 'off' position, while the model value is set to 'on'.

http://plnkr.co/edit/SsWwzJTiMn0cyNLM1Kpt?p=preview

Removing the timeout around element.bootstrapSwitch('state', newValue || false, true); seemed to fix the problem, but I'm unsure of other problems that may be caused by doing so.

First toggle do not change ngModel value (UPDATED)

Hi, I have also commented on the previous similar iissue but since it was closed I do not know if it is monitored...
So there is a problem when multiple bs-switches exist...
I found out that the problem is when you try to bind ng-model to an existing property of an object inside an array. If it is not the first element of the array and the property exists, it needs the first toggle cycle for binding to start working. If it is the first element it works no matter what directly

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.