Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 3642a1d

Browse files
authored
Merge pull request #1845 from Jefiozie/625_refreshOnActive
fix(#271) if option is set the refresh function is getting the request.
2 parents b549db9 + 914f2d8 commit 3642a1d

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/uiSelectChoicesDirective.js

+2-3
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.$watch('$select.search', function(newValue) {
@@ -79,7 +77,8 @@ uis.directive('uiSelectChoices',
7977

8078
scope.$watch('$select.open', function(open) {
8179
if (open) {
82-
element.attr('role', 'listbox');
80+
tElement.attr('role', 'listbox');
81+
$select.refresh(attrs.refresh);
8382
} else {
8483
element.removeAttr('role');
8584
}

src/uiSelectController.js

-4
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,8 @@ uis.controller('uiSelectCtrl',
114114
if(!avoidReset) _resetSearchInput();
115115

116116
$scope.$broadcast('uis:activate');
117-
118117
ctrl.open = true;
119-
120118
ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex;
121-
122119
// ensure that the index is set to zero for tagging variants
123120
// that where first option is auto-selected
124121
if ( ctrl.activeIndex === -1 && ctrl.taggingLabel !== false ) {
@@ -256,7 +253,6 @@ uis.controller('uiSelectCtrl',
256253
if (ctrl.dropdownPosition === 'auto' || ctrl.dropdownPosition === 'up'){
257254
$scope.calculateDropdownPos();
258255
}
259-
260256
$scope.$broadcast('uis:refresh');
261257
};
262258

test/select.spec.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -3231,7 +3231,31 @@ describe('ui-select tests', function() {
32313231
expect(el.scope().$select.spinnerClass).toBe('randomclass');
32323232
});
32333233
});
3234+
3235+
describe('With refresh on active', function(){
3236+
it('should refresh when is activated', function(){
3237+
scope.fetchFromServer = function(){};
3238+
var el = createUiSelect({refresh:"fetchFromServer($select.search)",refreshDelay:0});
3239+
spyOn(scope, 'fetchFromServer');
3240+
expect(el.scope().$select.open).toEqual(false);
3241+
el.scope().$select.activate();
3242+
$timeout.flush();
3243+
expect(el.scope().$select.open).toEqual(true);
3244+
expect(scope.fetchFromServer.calls.any()).toEqual(true);
3245+
});
3246+
32343247

3248+
it('should refresh when open is set to true', function(){
3249+
scope.fetchFromServer = function(){};
3250+
var el = createUiSelect({refresh:"fetchFromServer($select.search)",refreshDelay:0});
3251+
spyOn(scope, 'fetchFromServer');
3252+
expect(el.scope().$select.open).toEqual(false);
3253+
openDropdown(el);
3254+
$timeout.flush();
3255+
expect(el.scope().$select.open).toEqual(true);
3256+
expect(scope.fetchFromServer.calls.any()).toEqual(true);
3257+
});
3258+
});
32353259
describe('Test key down key up and activeIndex should skip disabled choice',function(){
32363260
it('should ignore disabled items, going down', function() {
32373261
var el = createUiSelect({uiDisableChoice:"person.age == 12"});
@@ -3295,5 +3319,4 @@ describe('ui-select tests', function() {
32953319
expect(el.scope().$select.activeIndex).toBe(2);
32963320
});
32973321
});
3298-
32993322
});

0 commit comments

Comments
 (0)