This repository was archived by the owner on Oct 2, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -454,9 +454,15 @@ uis.controller('uiSelectCtrl',
454
454
} ;
455
455
456
456
ctrl . clear = function ( $event ) {
457
+ var model = angular . copy ( ctrl . ngModel . $modelValue ) ;
458
+
457
459
ctrl . select ( null ) ;
458
460
$event . stopPropagation ( ) ;
459
461
$timeout ( function ( ) {
462
+ ctrl . onRemoveCallback ( $scope , {
463
+ $item : ctrl . items [ ctrl . activeIndex ] ,
464
+ $model : model
465
+ } ) ;
460
466
ctrl . focusser [ 0 ] . focus ( ) ;
461
467
} , 0 , false ) ;
462
468
} ;
Original file line number Diff line number Diff line change @@ -1425,6 +1425,35 @@ describe('ui-select tests', function () {
1425
1425
1426
1426
} ) ;
1427
1427
1428
+ it ( 'should invoke remove callback on remove for single select with allowClear enabled' , function ( ) {
1429
+ scope . selection . selected = scope . people [ 5 ] . name ;
1430
+
1431
+ scope . onRemoveFn = function ( $item , $model ) {
1432
+ scope . $item = $item ;
1433
+ scope . $model = $model ;
1434
+ } ;
1435
+
1436
+ var el = compileTemplate (
1437
+ '<ui-select on-remove="onRemoveFn($item, $model)" ng-model="selection.selected"> \
1438
+ <ui-select-match allow-clear="true" placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
1439
+ <ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
1440
+ <div ng-bind-html="person.name" | highlight: $select.search"></div> \
1441
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
1442
+ </ui-select-choices> \
1443
+ </ui-select>'
1444
+ ) ;
1445
+
1446
+ expect ( scope . $item ) . toBeFalsy ( ) ;
1447
+ expect ( scope . $model ) . toBeFalsy ( ) ;
1448
+
1449
+ el . find ( '.glyphicon.glyphicon-remove' ) . click ( ) ;
1450
+ $timeout . flush ( ) ;
1451
+
1452
+ expect ( scope . $item ) . toBe ( scope . people [ 5 ] ) ;
1453
+ expect ( scope . $model ) . toBe ( 'Samantha' ) ;
1454
+
1455
+ } ) ;
1456
+
1428
1457
it ( 'should set $item & $model correctly when invoking callback on remove and no single prop. binding' , function ( ) {
1429
1458
1430
1459
scope . onRemoveFn = function ( $item , $model , $label ) {
You can’t perform that action at this time.
0 commit comments