Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ng Disabled not working #36

Open
ido567 opened this issue Dec 15, 2015 · 3 comments
Open

Ng Disabled not working #36

ido567 opened this issue Dec 15, 2015 · 3 comments

Comments

@ido567
Copy link

ido567 commented Dec 15, 2015

The ng-disabled is not working. I changed the code a little bit is order to adjust the directive to the ng-disabled.
Hope you will update it on the repo

angular.module('uiSwitch', [])

.directive('switch', function(){
  return {
    restrict: 'AE'
  , replace: true
  , transclude: true
  , template: function(element, attrs) {
      var html = '';
      html += '<span';
      html +=   ' class="switch' + (attrs.class ? ' ' + attrs.class : '') + '"';
      html +=   attrs.ngModel ? ' ng-click="' + attrs.ngDisabled + ' ? ' + attrs.ngModel + ' : ' + attrs.ngModel + '=!' + attrs.ngModel + (attrs.ngChange ? '; ' + attrs.ngChange + '()"' : '"') : '';
      html +=   ' ng-class="{ checked:' + attrs.ngModel + ', disabled:' + attrs.ngDisabled + ' }"';
      html +=   '>';
      html +=   '<small></small>';
      html +=   '<input type="checkbox"';
      html +=     attrs.id ? ' id="' + attrs.id + '"' : '';
      html +=     attrs.name ? ' name="' + attrs.name + '"' : '';
      html +=     attrs.ngModel ? ' ng-model="' + attrs.ngModel + '"' : '';
      html +=     attrs.ngDisabled ? ' ng-disabled="' + attrs.ngDisabled +'"' : '';
      html +=     ' style="display:none" />';
      html +=     '<span class="switch-text">'; /*adding new container for switch text*/
      html +=     attrs.on ? '<span class="on">'+attrs.on+'</span>' : ''; /*switch text on value set by user in directive html markup*/
      html +=     attrs.off ? '<span class="off">'+attrs.off + '</span>' : ' ';  /*switch text off value set by user in directive html markup*/
      html += '</span>';
      return html;
    }
  }
});
ziliwesley added a commit to ziliwesley/angular-ui-switch that referenced this issue Jan 18, 2016
@AcarMeel
Copy link

is there a toggle method ? I mean I was struggling with this and copied this code and now I'm able to disable the switches, but I want to select a switch and disable the other one automatically...

@hjzheng
Copy link

hjzheng commented Jan 23, 2017

@AcarMeel you can use this ui-switch https://github.com/hjzheng/angular-switch

@YaboWei
Copy link

YaboWei commented Jul 7, 2017

That is worked.
html += attrs.ngModel ? ' ng-click="' + (attrs.disabled ? attrs.ngModel : attrs.ngModel + '=!' + attrs.ngModel) + (attrs.ngChange ? '; ' + attrs.ngChange + '()"' : '"') : '';

But the attrs.disabled is always true in ng-click. In ng-class, attrs.disabled works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants