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 +30
-6
lines changed Expand file tree Collapse file tree 2 files changed +30
-6
lines changed Original file line number Diff line number Diff line change 579
579
result ;
580
580
if ( $select . multiple ) {
581
581
var resultMultiple = [ ] ;
582
- for ( var j = inputValue . length - 1 ; j >= 0 ; j -- ) {
582
+ for ( var j = $select . selected . length - 1 ; j >= 0 ; j -- ) {
583
583
locals = { } ;
584
- locals [ $select . parserResult . itemName ] = inputValue [ j ] ;
584
+ locals [ $select . parserResult . itemName ] = $select . selected [ j ] ;
585
585
result = $select . parserResult . modelMapper ( scope , locals ) ;
586
586
resultMultiple . unshift ( result ) ;
587
587
}
730
730
} ) ;
731
731
732
732
if ( $select . multiple ) {
733
- scope . $watchCollection ( '$select.selected' , function ( newValue ) {
734
- //On v1.2.19 the 2nd and 3rd parameteres are ignored
735
- //On v1.3.0-beta+ 3rd parameter (revalidate) is true, to force $parsers to recreate model
736
- ngModel . $setViewValue ( newValue , null , true ) ;
733
+ scope . $watchCollection ( '$select.selected' , function ( ) {
734
+ ngModel . $setViewValue ( Date . now ( ) ) ; //Set timestamp as a unique string to force changes
737
735
} ) ;
738
736
focusser . prop ( 'disabled' , true ) ; //Focusser isn't needed if multiple
739
737
} else {
Original file line number Diff line number Diff line change @@ -1337,6 +1337,32 @@ describe('ui-select tests', function() {
1337
1337
1338
1338
} ) ;
1339
1339
1340
+ it ( 'should change viewvalue only once when updating modelvalue' , function ( ) {
1341
+
1342
+ scope . selection . selectedMultiple = [ 'wladimir@email.com' , 'samantha@email.com' ] ;
1343
+
1344
+ var el = compileTemplate (
1345
+ '<ui-select ng-change="onlyOnce()" multiple ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
1346
+ <ui-select-match placeholder="Pick one...">{{$item.name}} <{{$item.email}}></ui-select-match> \
1347
+ <ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
1348
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
1349
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
1350
+ </ui-select-choices> \
1351
+ </ui-select> \
1352
+ '
1353
+ ) ;
1354
+
1355
+ scope . counter = 0 ;
1356
+ scope . onlyOnce = function ( ) {
1357
+ scope . counter ++ ;
1358
+ }
1359
+
1360
+ clickItem ( el , 'Nicole' ) ;
1361
+
1362
+ expect ( scope . counter ) . toBe ( 1 ) ;
1363
+
1364
+ } ) ;
1365
+
1340
1366
} ) ;
1341
1367
1342
1368
You can’t perform that action at this time.
0 commit comments