Skip to content

Commit 92d0eae

Browse files
author
Rick Yang
committed
Merge pull request angular-ui#1845 from Jefiozie/625_refreshOnActive
fix(angular-ui#271) if option is set the refresh function is getting the request.
1 parent 3b00c3f commit 92d0eae

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/uiSelectChoicesDirective.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ uis.directive('uiSelectChoices',
5555

5656

5757
$select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult
58-
5958
$select.disableChoiceExpression = attrs.uiDisableChoice;
6059
$select.onHighlightCallback = attrs.onHighlight;
61-
6260
$select.dropdownPosition = attrs.position ? attrs.position.toLowerCase() : uiSelectConfig.dropdownPosition;
6361

6462
scope.$on('$destroy', function() {
@@ -84,6 +82,7 @@ uis.directive('uiSelectChoices',
8482
scope.$watch('$select.open', function(open) {
8583
if (open) {
8684
tElement.attr('role', 'listbox');
85+
$select.refresh(attrs.refresh);
8786
} else {
8887
tElement.removeAttr('role');
8988
}

src/uiSelectController.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,8 @@ uis.controller('uiSelectCtrl',
115115
if(!avoidReset) _resetSearchInput();
116116

117117
$scope.$broadcast('uis:activate');
118-
119118
ctrl.open = true;
120-
121119
ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex;
122-
123120
// ensure that the index is set to zero for tagging variants
124121
// that where first option is auto-selected
125122
if ( ctrl.activeIndex === -1 && ctrl.taggingLabel !== false ) {
@@ -257,7 +254,6 @@ uis.controller('uiSelectCtrl',
257254
if (ctrl.dropdownPosition === 'auto' || ctrl.dropdownPosition === 'up'){
258255
$scope.calculateDropdownPos();
259256
}
260-
261257
$scope.$broadcast('uis:refresh');
262258
};
263259

test/select.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,4 +3099,28 @@ describe('ui-select tests', function() {
30993099
});
31003100
});
31013101

3102+
describe('With refresh on active', function(){
3103+
it('should refresh when is activated', function(){
3104+
scope.fetchFromServer = function(){};
3105+
var el = createUiSelect({refresh:"fetchFromServer($select.search)",refreshDelay:0});
3106+
spyOn(scope, 'fetchFromServer');
3107+
expect(el.scope().$select.open).toEqual(false);
3108+
el.scope().$select.activate();
3109+
$timeout.flush();
3110+
expect(el.scope().$select.open).toEqual(true);
3111+
expect(scope.fetchFromServer.calls.any()).toEqual(true);
3112+
});
3113+
3114+
3115+
it('should refresh when open is set to true', function(){
3116+
scope.fetchFromServer = function(){};
3117+
var el = createUiSelect({refresh:"fetchFromServer($select.search)",refreshDelay:0});
3118+
spyOn(scope, 'fetchFromServer');
3119+
expect(el.scope().$select.open).toEqual(false);
3120+
openDropdown(el);
3121+
$timeout.flush();
3122+
expect(el.scope().$select.open).toEqual(true);
3123+
expect(scope.fetchFromServer.calls.any()).toEqual(true);
3124+
});
3125+
});
31023126
});

0 commit comments

Comments
 (0)