Skip to content

Commit 24975b5

Browse files
committed
Merge branch 'master' of https://github.com/abudel/ui-select into refactor_and_tidy
Conflicts: test/select.spec.js
2 parents af50d36 + 33f4d9f commit 24975b5

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/uiSelectChoicesDirective.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ uis.directive('uiSelectChoices',
2828
$select.disableChoiceExpression = attrs.uiDisableChoice;
2929
$select.onHighlightCallback = attrs.onHighlight;
3030

31+
$select.refreshOnActive = scope.$eval(attrs.refreshOnActive);
32+
3133
if(groupByExp) {
3234
var groups = element.querySelectorAll('.ui-select-choices-group');
3335
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',
5355
scope.$watch('$select.search', function(newValue) {
5456
if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
5557
$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+
}
5767
});
5868

5969
// $eval() is needed otherwise we get a string instead of a number

src/uiSelectController.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ uis.controller('uiSelectCtrl',
3838
ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function
3939
ctrl.clickTriggeredSelect = false;
4040
ctrl.$filter = $filter;
41+
ctrl.refreshOnActive = undefined;
42+
ctrl.refreshIsActive = undefined;
4143

4244
ctrl.searchInput = $element.querySelectorAll('input.ui-select-search');
4345
if (ctrl.searchInput.length !== 1) {
@@ -85,6 +87,8 @@ uis.controller('uiSelectCtrl',
8587

8688
ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex;
8789

90+
ctrl.refreshIsActive = true;
91+
8892
// ensure that the index is set to zero for tagging variants
8993
// that where first option is auto-selected
9094
if ( ctrl.activeIndex === -1 && ctrl.taggingLabel !== false ) {

test/select.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,4 +2254,32 @@ describe('ui-select tests', function() {
22542254
});
22552255
});
22562256

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+
});
22572285
});

0 commit comments

Comments
 (0)