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

Commit d89a869

Browse files
committed
Merge branch 'giorgiofellipe-feat/minimumInputLength'
2 parents f38afd2 + 0f9ca5d commit d89a869

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/uiSelectChoicesDirective.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ uis.directive('uiSelectChoices',
5454
scope.$watch('$select.search', function(newValue) {
5555
if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
5656
$select.activeIndex = $select.tagging.isActivated ? -1 : 0;
57-
$select.refresh(attrs.refresh);
57+
if (!attrs.minimumInputLength || $select.search.length >= attrs.minimumInputLength) {
58+
$select.refresh(attrs.refresh);
59+
} else {
60+
$select.items = [];
61+
}
5862
});
5963

6064
attrs.$observe('refreshDelay', function() {

test/select.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,37 @@ describe('ui-select tests', function() {
13981398

13991399
});
14001400

1401+
it('should call refresh function respecting minimum input length option', function () {
1402+
1403+
var el = compileTemplate(
1404+
'<ui-select ng-model="selection.selected"> \
1405+
<ui-select-match> \
1406+
</ui-select-match> \
1407+
<ui-select-choices repeat="person in people | filter: $select.search" \
1408+
refresh="fetchFromServer($select.search)" refresh-delay="0" minimum-input-length="3"> \
1409+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1410+
<div ng-if="person.name==\'Wladimir\'"> \
1411+
<span class="only-once">I should appear only once</span>\
1412+
</div> \
1413+
</ui-select-choices> \
1414+
</ui-select>'
1415+
);
1416+
1417+
scope.fetchFromServer = function(){};
1418+
1419+
spyOn(scope, 'fetchFromServer');
1420+
1421+
el.scope().$select.search = 'r';
1422+
scope.$digest();
1423+
$timeout.flush();
1424+
expect(scope.fetchFromServer).not.toHaveBeenCalledWith('r');
1425+
1426+
el.scope().$select.search = 'red';
1427+
scope.$digest();
1428+
$timeout.flush();
1429+
expect(scope.fetchFromServer).toHaveBeenCalledWith('red');
1430+
});
1431+
14011432
it('should format view value correctly when using single property binding and refresh function', function () {
14021433

14031434
var el = compileTemplate(

0 commit comments

Comments
 (0)