This repository was archived by the owner on Oct 2, 2019. It is now read-only.
File tree 2 files changed +36
-1
lines changed 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,11 @@ uis.directive('uiSelectChoices',
54
54
scope . $watch ( '$select.search' , function ( newValue ) {
55
55
if ( newValue && ! $select . open && $select . multiple ) $select . activate ( false , true ) ;
56
56
$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
+ }
58
62
} ) ;
59
63
60
64
attrs . $observe ( 'refreshDelay' , function ( ) {
Original file line number Diff line number Diff line change @@ -1398,6 +1398,37 @@ describe('ui-select tests', function() {
1398
1398
1399
1399
} ) ;
1400
1400
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
+
1401
1432
it ( 'should format view value correctly when using single property binding and refresh function' , function ( ) {
1402
1433
1403
1434
var el = compileTemplate (
You can’t perform that action at this time.
0 commit comments