Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit e3df778

Browse files
committed
fix(multiselect): run $formatters when changing model directly
1 parent 8477dcb commit e3df778

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/select.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,10 @@
749749
});
750750

751751
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+
});
752756
scope.$watchCollection('$select.selected', function() {
753757
ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes
754758
});

test/select.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,33 @@ describe('ui-select tests', function() {
14411441

14421442
});
14431443

1444+
1445+
it('should run $formatters when changing model directly', function () {
1446+
1447+
scope.selection.selectedMultiple = ['[email protected]', '[email protected]'];
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}} &lt;{{$item.email}}&gt;</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("[email protected]");
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 <[email protected]>Samantha <[email protected]>Nicole <[email protected]>");
1469+
1470+
});
14441471
});
14451472

14461473

0 commit comments

Comments
 (0)