Skip to content

Commit 2a8509f

Browse files
committed
changed watch of search as the initial value should be ignored on load
1 parent 91e48dd commit 2a8509f

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/uiSelectChoicesDirective.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ uis.directive('uiSelectChoices',
6363
choices.remove();
6464
});
6565

66-
scope.$watch('$select.search', function(newValue) {
67-
if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
66+
scope.$watch('$select.search', function(newValue, oldValue) {
67+
if(newValue !== "" && newValue !== oldValue && !$select.open && $select.multiple) $select.activate(false, true);
6868
$select.activeIndex = $select.tagging.isActivated ? -1 : 0;
69-
if ((!attrs.minimumInputLength || $select.search.length >= attrs.minimumInputLength) && $select.open) {
69+
if ((!attrs.minimumInputLength || $select.search.length >= attrs.minimumInputLength)) {
7070
$select.refresh(attrs.refresh);
7171
} else {
7272
$select.items = [];

test/select.spec.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ describe('ui-select tests', function() {
168168
if (attrs.refresh !== undefined) { choicesAttrsHtml += ' refresh="' + attrs.refresh + '"'; }
169169
if (attrs.refreshDelay !== undefined) { choicesAttrsHtml += ' refresh-delay="' + attrs.refreshDelay + '"'; }
170170
if (attrs.backspaceReset !== undefined) { attrsHtml += ' backspace-reset="' + attrs.backspaceReset + '"';}
171-
if (attrs.refreshOnActive !== undefined) { choicesAttrsHtml += ' refresh-on-active="' + attrs.refreshOnActive + '"'; }
172171

173172
}
174173

@@ -3123,14 +3122,25 @@ describe('ui-select tests', function() {
31233122
});
31243123

31253124
describe('With refresh on active', function(){
3126-
it('should not refresh untill is activated', function(){
3125+
it('should refresh when is activated', function(){
31273126
scope.fetchFromServer = function(){};
3128-
var el = createUiSelect({refresh:"fetchFromServer($select.search)",refreshOnActive:true,refreshDelay:0});
3129-
spyOn(scope, 'fetchFromServer');
3130-
$timeout.flush();
3131-
expect(scope.fetchFromServer.calls.any()).toEqual(false);
3127+
var el = createUiSelect({refresh:"fetchFromServer($select.search)",refreshDelay:0});
3128+
spyOn(scope, 'fetchFromServer');
3129+
expect(el.scope().$select.open).toEqual(false);
31323130
el.scope().$select.activate();
31333131
$timeout.flush();
3132+
expect(el.scope().$select.open).toEqual(true);
3133+
expect(scope.fetchFromServer.calls.any()).toEqual(true);
3134+
});
3135+
3136+
it('should refresh when open is set to true', function(){
3137+
scope.fetchFromServer = function(){};
3138+
var el = createUiSelect({refresh:"fetchFromServer($select.search)",refreshDelay:0});
3139+
spyOn(scope, 'fetchFromServer');
3140+
expect(el.scope().$select.open).toEqual(false);
3141+
openDropdown(el);
3142+
$timeout.flush();
3143+
expect(el.scope().$select.open).toEqual(true);
31343144
expect(scope.fetchFromServer.calls.any()).toEqual(true);
31353145
});
31363146
});

0 commit comments

Comments
 (0)