Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Fix uibUncheckable for uibBtnRadio #6538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/buttons/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ angular.module('ui.bootstrap.buttons', [])

if (attrs.uibUncheckable) {
scope.$watch(uncheckableExpr, function(uncheckable) {
attrs.$set('uncheckable', uncheckable ? '' : undefined);
attrs.$set('disabled', uncheckable ? 'disabled' : undefined);
});
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/buttons/docs/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ <h4>Radio &amp; Uncheckable Radio</h4>
<label class="btn btn-primary" ng-model="radioModel" uib-btn-radio="'Right'">Right</label>
</div>
<div class="btn-group">
<label class="btn btn-success" ng-model="radioModel" uib-btn-radio="'Left'" uncheckable>Left</label>
<label class="btn btn-success" ng-model="radioModel" uib-btn-radio="'Middle'" uncheckable>Middle</label>
<label class="btn btn-success" ng-model="radioModel" uib-btn-radio="'Left'" uib-uncheckable="uncheckable">Left</label>
<label class="btn btn-success" ng-model="radioModel" uib-btn-radio="'Middle'">Middle</label>
<label class="btn btn-success" ng-model="radioModel" uib-btn-radio="'Right'" uib-uncheckable="uncheckable">Right</label>
</div>
<br/>
<div>
<button class="btn btn-default" ng-click="uncheckable = !uncheckable">
Toggle uncheckable
</button>
&nbsp;
uncheckable: {{uncheckable}}
</div>
</div>
14 changes: 7 additions & 7 deletions src/buttons/test/buttons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ describe('buttons', function() {
});

describe('uibUncheckable', function() {
it('should set uncheckable', function() {
it('should set disabled', function() {
$scope.uncheckable = false;
var btns = compileButtons('<button ng-model="model" uib-btn-radio="1">click1</button><button ng-model="model" uib-btn-radio="2" uib-uncheckable="uncheckable">click2</button>', $scope);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the tests was made with button tags and the demo was made with label tags?

expect(btns.eq(0).attr('uncheckable')).toBeUndefined();
expect(btns.eq(1).attr('uncheckable')).toBeUndefined();
expect(btns.eq(0).attr('disabled')).toBeUndefined();
expect(btns.eq(1).attr('disabled')).toBeUndefined();

expect($scope.model).toBeUndefined();

Expand All @@ -346,8 +346,8 @@ describe('buttons', function() {

$scope.uncheckable = true;
$scope.$digest();
expect(btns.eq(0).attr('uncheckable')).toBeUndefined();
expect(btns.eq(1).attr('uncheckable')).toBeDefined();
expect(btns.eq(0).attr('disabled')).toBeUndefined();
expect(btns.eq(1).attr('disabled')).toBeDefined();

btns.eq(0).click();
expect($scope.model).toEqual(1);
Expand All @@ -356,10 +356,10 @@ describe('buttons', function() {
expect($scope.model).toEqual(1);

btns.eq(1).click();
expect($scope.model).toEqual(2);
expect($scope.model).toEqual(1);

btns.eq(1).click();
expect($scope.model).toBeNull();
expect($scope.model).toEqual(1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test was wrong. If I click a disabled button the value should not change or should not be converted to null.

});
});
});
Expand Down