Skip to content
This repository was archived by the owner on Dec 16, 2019. It is now read-only.

Commit 3abeb16

Browse files
committed
Added option to disable element
Setting the field disabled of an option to true will disable that option, if the option was previously checked it will still stay checked and will not be able to be unchecked. Implements #239
1 parent bdf18ef commit 3abeb16

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

pages/javascripts/pages/home/ExampleCtrl.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
angular.module('exampleApp').controller('ExampleCtrl', ['$scope', function($scope) {
44
$scope.testmodel = [];
55
$scope.testdata = [
6-
{ id: 1, label: "David"},
6+
{ id: 1, label: "David", disabled: true},
77
{ id: 2, label: "Jhon"},
88
{ id: 3, label: "Danny"}];
99
$scope.testsettings = {
@@ -246,4 +246,11 @@ angular.module('exampleApp').controller('ExampleCtrl', ['$scope', function($scop
246246
enableSearch: true,
247247
keyboardControls: true
248248
};
249+
250+
$scope.disabledModel = [];
251+
$scope.disabledData = [
252+
{ id: 1, label: "David", disabled: true},
253+
{ id: 2, label: "Jhon"},
254+
{ id: 3, label: "Danny"}
255+
];
249256
}]);

pages/javascripts/pages/home/home.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,45 @@ <h3>Code</h3>
864864
</div>
865865
</div>
866866
</uib-accordion-group>
867+
<uib-accordion-group heading="Disable Option">
868+
<div class="row">
869+
<div class="col-xs-12">
870+
Setting the field disabled of an option to true will disable that option, if the option was previously
871+
checked it will still stay checked and will not be able to be unchecked.
872+
</div>
873+
</div>
874+
<div class="row">
875+
<div class="col-xs-12 col-sm-6">
876+
<h3>Demo</h3>
877+
<div class="well">
878+
<div>
879+
<div ng-dropdown-multiselect="" options="disabledData" selected-model="disabledModel"></div>
880+
</div>
881+
</div>
882+
</div>
883+
<div class="col-xs-12 col-sm-6">
884+
<h3>The model:</h3>
885+
<pre>{{disabledModel|json}}</pre>
886+
</div>
887+
</div>
888+
<div class="row">
889+
<div class="col-md-12">
890+
<h3>Code</h3>
891+
<div hljs language="javascript">
892+
// HTML
893+
<div ng-dropdown-multiselect="" options="disabledData" selected-model="disabledModel"></div>
894+
895+
// JavaScript
896+
$scope.disabledModel = [];
897+
$scope.disabledData = [
898+
{ id: 1, label: "David", disabled: true},
899+
{ id: 2, label: "Jhon"},
900+
{ id: 3, label: "Danny"}
901+
];
902+
</div>
903+
</div>
904+
</div>
905+
</uib-accordion-group>
867906
</uib-accordion>
868907
<h1>Full API Documentation</h1>
869908
<h2>Attributes</h2>

pages/stylesheets/stylesheet.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ footer a:hover {
402402
padding-right: 0;
403403
margin-left: 0;
404404
}
405+
406+
a.option[disabled] {
407+
opacity: 0.5;
408+
}
405409
}
406410
/* Mobile Landscape Size to Tablet Portrait (devices and browsers) */
407411
@media only screen and (min-width: 480px) and (max-width: 767px) {

src/angularjs-dropdown-multiselect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co
4646
template += '<li ng-class="{\'active\': isChecked(getPropertyForObject(option,settings.idProp)) && settings.styleActive}" role="presentation" ng-repeat="option in options | filter:getFilter(input.searchFilter)">';
4747
}
4848

49-
template += '<a ng-keydown="keyDownLink($event)" role="menuitem" class="option" tabindex="-1" ng-click="setSelectedItem(getPropertyForObject(option,settings.idProp), false, true)">';
49+
template += '<a ng-keydown="option.disabled || keyDownLink($event)" role="menuitem" class="option" tabindex="-1" ng-click="option.disabled || setSelectedItem(getPropertyForObject(option,settings.idProp), false, true)" ng-disabled="option.disabled">';
5050

5151
if (checkboxes) {
5252
template += '<div class="checkbox"><label><input class="checkboxInput" type="checkbox" ng-click="checkboxClick($event, getPropertyForObject(option,settings.idProp))" ng-checked="isChecked(getPropertyForObject(option,settings.idProp))" /> <span mf-dropdown-static-include="{{settings.template}}"></div></label></span></a>';

0 commit comments

Comments
 (0)