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 +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 749
749
} ) ;
750
750
751
751
if ( $select . multiple ) {
752
+ scope . $watchCollection ( function ( ) { return ngModel . $modelValue ; } , function ( newValue , oldValue ) {
753
+ if ( oldValue != newValue )
754
+ ngModel . $modelValue = null ; //Force scope model value and ngModel value to be out of sync to re-run formatters
755
+ } ) ;
752
756
scope . $watchCollection ( '$select.selected' , function ( ) {
753
757
ngModel . $setViewValue ( Date . now ( ) ) ; //Set timestamp as a unique string to force changes
754
758
} ) ;
Original file line number Diff line number Diff line change @@ -1441,6 +1441,33 @@ describe('ui-select tests', function() {
1441
1441
1442
1442
} ) ;
1443
1443
1444
+
1445
+ it ( 'should run $formatters when changing model directly' , function ( ) {
1446
+
1447
+ scope . selection . selectedMultiple = [ 'wladimir@email.com' , 'samantha@email.com' ] ;
1448
+
1449
+ var el = compileTemplate (
1450
+ '<ui-select multiple ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
1451
+ <ui-select-match placeholder="Pick one...">{{$item.name}} <{{$item.email}}></ui-select-match> \
1452
+ <ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
1453
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
1454
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
1455
+ </ui-select-choices> \
1456
+ </ui-select> \
1457
+ '
1458
+ ) ;
1459
+
1460
+ // var el2 = compileTemplate('<span class="resultDiv" ng-bind="selection.selectedMultiple"></span>');
1461
+
1462
+ scope . selection . selectedMultiple . push ( "nicole@email.com" ) ;
1463
+
1464
+ scope . $digest ( ) ;
1465
+ scope . $digest ( ) ; //2nd $digest needed when using angular 1.3.0-rc.1+, might be related with the fact that the value is an array
1466
+
1467
+ expect ( el . find ( '.ui-select-match-item [uis-transclude-append]:not(.ng-hide)' ) . text ( ) )
1468
+ . toBe ( "Wladimir <wladimir@email.com>Samantha <samantha@email.com>Nicole <nicole@email.com>" ) ;
1469
+
1470
+ } ) ;
1444
1471
} ) ;
1445
1472
1446
1473
You can’t perform that action at this time.
0 commit comments