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 763
763
} ) ;
764
764
765
765
if ( $select . multiple ) {
766
+ scope . $watchCollection ( function ( ) { return ngModel . $modelValue ; } , function ( newValue , oldValue ) {
767
+ if ( oldValue != newValue )
768
+ ngModel . $modelValue = null ; //Force scope model value and ngModel value to be out of sync to re-run formatters
769
+ } ) ;
766
770
scope . $watchCollection ( '$select.selected' , function ( ) {
767
771
ngModel . $setViewValue ( Date . now ( ) ) ; //Set timestamp as a unique string to force changes
768
772
} ) ;
Original file line number Diff line number Diff line change @@ -1443,6 +1443,33 @@ describe('ui-select tests', function() {
1443
1443
1444
1444
} ) ;
1445
1445
1446
+
1447
+ it ( 'should run $formatters when changing model directly' , function ( ) {
1448
+
1449
+ scope . selection . selectedMultiple = [ 'wladimir@email.com' , 'samantha@email.com' ] ;
1450
+
1451
+ var el = compileTemplate (
1452
+ '<ui-select multiple ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
1453
+ <ui-select-match placeholder="Pick one...">{{$item.name}} <{{$item.email}}></ui-select-match> \
1454
+ <ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
1455
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
1456
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
1457
+ </ui-select-choices> \
1458
+ </ui-select> \
1459
+ '
1460
+ ) ;
1461
+
1462
+ // var el2 = compileTemplate('<span class="resultDiv" ng-bind="selection.selectedMultiple"></span>');
1463
+
1464
+ scope . selection . selectedMultiple . push ( "nicole@email.com" ) ;
1465
+
1466
+ scope . $digest ( ) ;
1467
+ 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
1468
+
1469
+ expect ( el . find ( '.ui-select-match-item [uis-transclude-append]:not(.ng-hide)' ) . text ( ) )
1470
+ . toBe ( "Wladimir <wladimir@email.com>Samantha <samantha@email.com>Nicole <nicole@email.com>" ) ;
1471
+
1472
+ } ) ;
1446
1473
} ) ;
1447
1474
1448
1475
You can’t perform that action at this time.
0 commit comments