This repository was archived by the owner on Oct 2, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +34
-5
lines changed Expand file tree Collapse file tree 2 files changed +34
-5
lines changed Original file line number Diff line number Diff line change 1242
1242
$select . disableChoiceExpression = attrs . uiDisableChoice ;
1243
1243
$select . onHighlightCallback = attrs . onHighlight ;
1244
1244
1245
- $select . refreshOnActive = attrs . refreshOnActive ;
1245
+ $select . refreshOnActive = scope . $eval ( attrs . refreshOnActive ) ;
1246
1246
1247
1247
if ( groupByExp ) {
1248
1248
var groups = element . querySelectorAll ( '.ui-select-choices-group' ) ;
1269
1269
scope . $watch ( '$select.search' , function ( newValue ) {
1270
1270
if ( newValue && ! $select . open && $select . multiple ) $select . activate ( false , true ) ;
1271
1271
$select . activeIndex = $select . tagging . isActivated ? - 1 : 0 ;
1272
- if ( angular . isUndefined ( $select . refreshOnActive ) || ( $select . refreshOnActive && $select . refreshIsActive ) ) {
1272
+ if ( ! $select . refreshOnActive || ( $select . refreshOnActive && $select . refreshIsActive ) ) {
1273
1273
$select . refresh ( attrs . refresh ) ;
1274
1274
}
1275
1275
} ) ;
1276
1276
1277
- scope . $watch ( '$select.refreshIsActive' , function ( value ) {
1278
- if ( angular . isUndefined ( value ) ) {
1277
+ scope . $watch ( '$select.refreshIsActive' , function ( newValue , oldValue ) {
1278
+ if ( angular . isUndefined ( oldValue ) && newValue ) {
1279
1279
$select . refresh ( attrs . refresh ) ;
1280
1280
}
1281
1281
} ) ;
Original file line number Diff line number Diff line change @@ -158,7 +158,7 @@ describe('ui-select tests', function() {
158
158
159
159
expect ( getMatchLabel ( el ) ) . toEqual ( 'Adam' ) ;
160
160
} ) ;
161
-
161
+
162
162
it ( 'should correctly render initial state with track by feature' , function ( ) {
163
163
var el = compileTemplate (
164
164
'<ui-select ng-model="selection.selected"> \
@@ -1700,4 +1700,33 @@ describe('ui-select tests', function() {
1700
1700
}
1701
1701
} ) ;
1702
1702
} ) ;
1703
+
1704
+ describe ( 'with refresh on active' , function ( ) {
1705
+ it ( 'should not refresh untill is activate' , function ( ) {
1706
+
1707
+ var el = compileTemplate (
1708
+ '<ui-select ng-model="selection.selected"> \
1709
+ <ui-select-match> \
1710
+ </ui-select-match> \
1711
+ <ui-select-choices repeat="person in people | filter: $select.search" \
1712
+ refresh="fetchFromServer($select.search)" refresh-on-active="true" refresh-delay="0"> \
1713
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
1714
+ <div ng-if="person.name==\'Wladimir\'"> \
1715
+ <span class="only-once">I should appear only once</span>\
1716
+ </div> \
1717
+ </ui-select-choices> \
1718
+ </ui-select>'
1719
+ ) ;
1720
+
1721
+ scope . fetchFromServer = function ( ) { } ;
1722
+ spyOn ( scope , 'fetchFromServer' ) ;
1723
+ $timeout . flush ( ) ;
1724
+ expect ( scope . fetchFromServer . calls . any ( ) ) . toEqual ( false ) ;
1725
+
1726
+ el . scope ( ) . $select . activate ( ) ;
1727
+ $timeout . flush ( ) ;
1728
+ expect ( scope . fetchFromServer . calls . any ( ) ) . toEqual ( true ) ;
1729
+ } ) ;
1730
+
1731
+ } ) ;
1703
1732
} ) ;
You can’t perform that action at this time.
0 commit comments