This repository was archived by the owner on Oct 2, 2019. It is now read-only.
File tree 3 files changed +45
-2
lines changed 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ uis.directive('uiSelectChoices',
27
27
$select . disableChoiceExpression = attrs . uiDisableChoice ;
28
28
$select . onHighlightCallback = attrs . onHighlight ;
29
29
30
+ $select . refreshOnActive = scope . $eval ( attrs . refreshOnActive ) ;
31
+
30
32
if ( groupByExp ) {
31
33
var groups = element . querySelectorAll ( '.ui-select-choices-group' ) ;
32
34
if ( groups . length !== 1 ) throw uiSelectMinErr ( 'rows' , "Expected 1 .ui-select-choices-group but got '{0}'." , groups . length ) ;
@@ -52,7 +54,15 @@ uis.directive('uiSelectChoices',
52
54
scope . $watch ( '$select.search' , function ( newValue ) {
53
55
if ( newValue && ! $select . open && $select . multiple ) $select . activate ( false , true ) ;
54
56
$select . activeIndex = $select . tagging . isActivated ? - 1 : 0 ;
55
- $select . refresh ( attrs . refresh ) ;
57
+ if ( ! $select . refreshOnActive || ( $select . refreshOnActive && $select . refreshIsActive ) ) {
58
+ $select . refresh ( attrs . refresh ) ;
59
+ }
60
+ } ) ;
61
+
62
+ scope . $watch ( '$select.refreshIsActive' , function ( newValue , oldValue ) {
63
+ if ( angular . isUndefined ( oldValue ) && newValue ) {
64
+ $select . refresh ( attrs . refresh ) ;
65
+ }
56
66
} ) ;
57
67
58
68
attrs . $observe ( 'refreshDelay' , function ( ) {
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ uis.controller('uiSelectCtrl',
34
34
ctrl . closeOnSelect = true ; // Initialized inside uiSelect directive link function
35
35
ctrl . clickTriggeredSelect = false ;
36
36
ctrl . $filter = $filter ;
37
+ ctrl . refreshOnActive = undefined ;
38
+ ctrl . refreshIsActive = undefined ;
37
39
38
40
ctrl . isEmpty = function ( ) {
39
41
return angular . isUndefined ( ctrl . selected ) || ctrl . selected === null || ctrl . selected === '' ;
@@ -65,6 +67,8 @@ uis.controller('uiSelectCtrl',
65
67
66
68
ctrl . activeIndex = ctrl . activeIndex >= ctrl . items . length ? 0 : ctrl . activeIndex ;
67
69
70
+ ctrl . refreshIsActive = true ;
71
+
68
72
// ensure that the index is set to zero for tagging variants
69
73
// that where first option is auto-selected
70
74
if ( ctrl . activeIndex === - 1 && ctrl . taggingLabel !== false ) {
Original file line number Diff line number Diff line change @@ -191,7 +191,7 @@ describe('ui-select tests', function() {
191
191
192
192
expect ( getMatchLabel ( el ) ) . toEqual ( 'Adam' ) ;
193
193
} ) ;
194
-
194
+
195
195
it ( 'should correctly render initial state with track by feature' , function ( ) {
196
196
var el = compileTemplate (
197
197
'<ui-select ng-model="selection.selected"> \
@@ -1791,4 +1791,33 @@ describe('ui-select tests', function() {
1791
1791
}
1792
1792
} ) ;
1793
1793
} ) ;
1794
+
1795
+ describe ( 'with refresh on active' , function ( ) {
1796
+ it ( 'should not refresh untill is activate' , function ( ) {
1797
+
1798
+ var el = compileTemplate (
1799
+ '<ui-select ng-model="selection.selected"> \
1800
+ <ui-select-match> \
1801
+ </ui-select-match> \
1802
+ <ui-select-choices repeat="person in people | filter: $select.search" \
1803
+ refresh="fetchFromServer($select.search)" refresh-on-active="true" refresh-delay="0"> \
1804
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
1805
+ <div ng-if="person.name==\'Wladimir\'"> \
1806
+ <span class="only-once">I should appear only once</span>\
1807
+ </div> \
1808
+ </ui-select-choices> \
1809
+ </ui-select>'
1810
+ ) ;
1811
+
1812
+ scope . fetchFromServer = function ( ) { } ;
1813
+ spyOn ( scope , 'fetchFromServer' ) ;
1814
+ $timeout . flush ( ) ;
1815
+ expect ( scope . fetchFromServer . calls . any ( ) ) . toEqual ( false ) ;
1816
+
1817
+ el . scope ( ) . $select . activate ( ) ;
1818
+ $timeout . flush ( ) ;
1819
+ expect ( scope . fetchFromServer . calls . any ( ) ) . toEqual ( true ) ;
1820
+ } ) ;
1821
+
1822
+ } ) ;
1794
1823
} ) ;
You can’t perform that action at this time.
0 commit comments