File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ uis.directive('uiSelectChoices',
28
28
$select . disableChoiceExpression = attrs . uiDisableChoice ;
29
29
$select . onHighlightCallback = attrs . onHighlight ;
30
30
31
+ $select . refreshOnActive = scope . $eval ( attrs . refreshOnActive ) ;
32
+
31
33
if ( groupByExp ) {
32
34
var groups = element . querySelectorAll ( '.ui-select-choices-group' ) ;
33
35
if ( groups . length !== 1 ) throw uiSelectMinErr ( 'rows' , "Expected 1 .ui-select-choices-group but got '{0}'." , groups . length ) ;
@@ -53,7 +55,15 @@ uis.directive('uiSelectChoices',
53
55
scope . $watch ( '$select.search' , function ( newValue ) {
54
56
if ( newValue && ! $select . open && $select . multiple ) $select . activate ( false , true ) ;
55
57
$select . activeIndex = $select . tagging . isActivated ? - 1 : 0 ;
56
- $select . refresh ( attrs . refresh ) ;
58
+ if ( ! $select . refreshOnActive || ( $select . refreshOnActive && $select . refreshIsActive ) ) {
59
+ $select . refresh ( attrs . refresh ) ;
60
+ }
61
+ } ) ;
62
+
63
+ scope . $watch ( '$select.refreshIsActive' , function ( newValue , oldValue ) {
64
+ if ( angular . isUndefined ( oldValue ) && newValue ) {
65
+ $select . refresh ( attrs . refresh ) ;
66
+ }
57
67
} ) ;
58
68
59
69
// $eval() is needed otherwise we get a string instead of a number
Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ uis.controller('uiSelectCtrl',
38
38
ctrl . lockChoiceExpression = undefined ; // Initialized inside uiSelectMatch directive link function
39
39
ctrl . clickTriggeredSelect = false ;
40
40
ctrl . $filter = $filter ;
41
+ ctrl . refreshOnActive = undefined ;
42
+ ctrl . refreshIsActive = undefined ;
41
43
42
44
ctrl . searchInput = $element . querySelectorAll ( 'input.ui-select-search' ) ;
43
45
if ( ctrl . searchInput . length !== 1 ) {
@@ -85,6 +87,8 @@ uis.controller('uiSelectCtrl',
85
87
86
88
ctrl . activeIndex = ctrl . activeIndex >= ctrl . items . length ? 0 : ctrl . activeIndex ;
87
89
90
+ ctrl . refreshIsActive = true ;
91
+
88
92
// ensure that the index is set to zero for tagging variants
89
93
// that where first option is auto-selected
90
94
if ( ctrl . activeIndex === - 1 && ctrl . taggingLabel !== false ) {
Original file line number Diff line number Diff line change @@ -2254,4 +2254,32 @@ describe('ui-select tests', function() {
2254
2254
} ) ;
2255
2255
} ) ;
2256
2256
2257
+ describe ( 'with refresh on active' , function ( ) {
2258
+ it ( 'should not refresh untill is activate' , function ( ) {
2259
+
2260
+ var el = compileTemplate (
2261
+ '<ui-select ng-model="selection.selected"> \
2262
+ <ui-select-match> \
2263
+ </ui-select-match> \
2264
+ <ui-select-choices repeat="person in people | filter: $select.search" \
2265
+ refresh="fetchFromServer($select.search)" refresh-on-active="true" refresh-delay="0"> \
2266
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
2267
+ <div ng-if="person.name==\'Wladimir\'"> \
2268
+ <span class="only-once">I should appear only once</span>\
2269
+ </div> \
2270
+ </ui-select-choices> \
2271
+ </ui-select>'
2272
+ ) ;
2273
+
2274
+ scope . fetchFromServer = function ( ) { } ;
2275
+ spyOn ( scope , 'fetchFromServer' ) ;
2276
+ $timeout . flush ( ) ;
2277
+ expect ( scope . fetchFromServer . calls . any ( ) ) . toEqual ( false ) ;
2278
+
2279
+ el . scope ( ) . $select . activate ( ) ;
2280
+ $timeout . flush ( ) ;
2281
+ expect ( scope . fetchFromServer . calls . any ( ) ) . toEqual ( true ) ;
2282
+ } ) ;
2283
+
2284
+ } ) ;
2257
2285
} ) ;
You can’t perform that action at this time.
0 commit comments