This repository was archived by the owner on Oct 2, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +41
-4
lines changed Expand file tree Collapse file tree 4 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 87
87
</ div >
88
88
</ div >
89
89
90
+ < div class ="form-group ">
91
+ < label class ="col-sm-3 control-label "> Disabled</ label >
92
+ < div class ="col-sm-6 ">
93
+
94
+ < ui-select ng-model ="person.selected " theme ="select2 " class ="form-control " ng-disabled ="true ">
95
+ < match placeholder ="Select or search a person in the list... "> {{$select.selected.name}}</ match >
96
+ < choices repeat ="item in people | filter: $select.search ">
97
+ < div ng-bind-html ="trustAsHtml((item.name | highlight: $select.search)) "> </ div >
98
+ < small ng-bind-html ="trustAsHtml((item.email | highlight: $select.search)) "> </ small >
99
+ </ choices >
100
+ </ ui-select >
101
+
102
+ </ div >
103
+ </ div >
104
+
90
105
</ fieldset >
91
106
</ form >
92
107
Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ angular.module('ui.select', [])
69
69
var $select = controllers [ 0 ] ;
70
70
var ngModelCtrl = controllers [ 1 ] ;
71
71
72
+ attrs . $observe ( 'disabled' , function ( ) {
73
+ $select . disabled = attrs . disabled ? true : false ;
74
+ } ) ;
75
+
72
76
scope . $watch ( '$select.selected' , function ( newVal , oldVal ) {
73
77
if ( ngModelCtrl . $viewValue !== newVal ) ngModelCtrl . $setViewValue ( newVal ) ;
74
78
} ) ;
Original file line number Diff line number Diff line change 1
1
< div class ="select2 select2-container "
2
- ng-class ="{'select2-container-active select2-dropdown-open': $select.open} ">
2
+ ng-class ="{'select2-container-active select2-dropdown-open': $select.open && !$select.disabled,
3
+ 'select2-container-disabled': $select.disabled} ">
3
4
< div class ="ui-select-match "> </ div >
4
- < div ng-class ="{'select2-display-none': !$select.open} "
5
+ < div ng-class ="{'select2-display-none': !$select.open || $select.disabled } "
5
6
class ="select2-drop select2-with-searchbox select2-drop-active ">
6
7
< div class ="select2-search ">
7
8
< input type ="text "
Original file line number Diff line number Diff line change @@ -27,9 +27,15 @@ describe('ui-select tests', function() {
27
27
return el ;
28
28
}
29
29
30
- function createUiSelect ( ) {
30
+ function createUiSelect ( attrs ) {
31
+ var attrsHtml = '' ;
32
+ if ( attrs !== undefined ) {
33
+ if ( attrs . disabled !== undefined ) { attrsHtml += ' ng-disabled="' + attrs . disabled + '"' ; }
34
+ if ( attrs . required !== undefined ) { attrsHtml += ' ng-required="' + attrs . required + '"' ; }
35
+ }
36
+
31
37
return compileTemplate (
32
- '<ui-select ng-model="selection"> \
38
+ '<ui-select ng-model="selection"' + attrsHtml + ' > \
33
39
<match placeholder="Pick one...">{{$select.selected.name}}</match> \
34
40
<choices repeat="item in matches | filter: $select.search"> \
35
41
<div ng-bind-html="trustAsHtml((item.name | highlight: $select.search))"></div> \
@@ -140,4 +146,15 @@ describe('ui-select tests', function() {
140
146
141
147
expect ( el . scope ( ) . $select . open ) . toEqual ( false ) ;
142
148
} ) ;
149
+
150
+ it ( 'should be disabled if the attribute says so' , function ( ) {
151
+ var el1 = createUiSelect ( { disabled : true } ) ;
152
+ expect ( el1 . scope ( ) . $select . disabled ) . toEqual ( true ) ;
153
+
154
+ var el2 = createUiSelect ( { disabled : false } ) ;
155
+ expect ( el2 . scope ( ) . $select . disabled ) . toEqual ( false ) ;
156
+
157
+ var el3 = createUiSelect ( ) ;
158
+ expect ( el3 . scope ( ) . $select . disabled ) . toEqual ( false ) ;
159
+ } ) ;
143
160
} ) ;
You can’t perform that action at this time.
0 commit comments